我有一個lightbox插件,需要額外的選項 - 打印圖像。 所以我做了打印圖像如下一點的JS函數:window.print()javascript does not get previewed in chrome
var headstr="<!DOCUMENT html><html xmlns='http://www.w3.org/1999/xhtml'><head><title></title></head><body>";
var footstr="</body>";
var newstr="<img src=\"[img-location]\" alt='courses' />";
document.body.innerHTML=headstr+newstr+footstr;
window.print();
window.location.reload();
的問題是,當打印按鈕,用戶按下後,chrome它會打開一個新窗口(鉻打印頁),並在其中它說 - print preview failed。在Firefox和IE8中,它工作得很好...
我加一個結束的HTML標籤,但有什麼不妥:
該結構適用於整個頁面,但您將其插入到body \ document.body.innerHTML'中。所以,你已經有了'
哦,對了,我該怎麼辦文件= headstr + +中newstr footstr?我想要它,因爲它也刪除了現有的標題內容 – Nir