我創建了這個代碼從一個iFrame如何使用樣式表打印iFrame?
function (data) {
var frame = $("<iframe>", {
name: "iFrame",
class: "printFrame"
});
frame.appendTo("body");
var head = $("<head></head>");
_.each($("head link[rel=stylesheet]"), function (link) {
var csslink = $("<link/>", { rel: "stylesheet", href: $(link).prop("href") })
head.append(csslink);
;});
frame.contents().find("head")
.replaceWith(head);
frame.contents().find("body")
.append(this.html());
window.frames["iFrame"].focus();
window.frames["iFrame"].print();
}
這將創建一個iFrame打印數據,增加了一個頭,在那裏設置所需要本網站所有的CSS鏈接。然後它創建身體。
問題是,造型不會適用於打印,除非我在第行break.contents()。find(「head」)。replaceWith(head),這意味着該部分正在異步運行。
問題是,我可以以某種方式獲得代碼在運行該行之前等待一段時間,或者可能有另一種方法來執行此操作?不幸的是,我並不熟悉iFrames,所以我不知道它在嘗試做什麼。
https://stackoverflow.com/questions/9616426/javascript-print-iframe-contents-only –
@SagarSinha不知道你想要通過鏈接該頁面。你能否解釋一些更多的或評論你想要參考的那個線索的哪一部分? – Hofftari