[英]Add DIV to popup window with javascript
因此,我有一個包含CSS的HTML文檔,該CSS定義了DIV頁面的布局。 我想打開一個新窗口,並將DIV添加到包含來自數組的信息的該窗口中。 document.write將不起作用,因為它會刪除現有頁面,從而刪除CSS。 我已經嘗試過newwindow.document.body.appendChild(),但是什么也沒有出現。 我想念什么?
編輯:好的,事實證明我的代碼可以在IE中按預期工作,但在我正在測試的Chrome中卻沒有。 這似乎是一項安全措施,無法將其關閉。
var printWindow = window.open("widgets/eSearchPlus/this_is_a_test.html", "PrintLabels", "toolbar=yes, location=no, directories=no, status=no, menubar=no, scrollbars=yes, resizable=yes, width=780, height=200, top="+(screen.height-400)+", left="+(screen.width-840));
var div = document.createElement('div');
div.className = "label";
div.innerHTML = "test";
printWindow.document.body.appendChild(div);
嘗試這個:
var printWindow = window.open("widgets/eSearchPlus/this_is_a_test.html", "PrintLabels", "toolbar=yes, location=no, directories=no, status=no, menubar=no, scrollbars=yes, resizable=yes, width=780, height=200, top="+(screen.height-400)+", left="+(screen.width-840));
printWindow.document.body.innerHTML += '<div class="label">test</div>';
您的問題可能是您正在父窗口中創建一個元素,然后嘗試將其添加到子窗口中。
嘗試更改要在子窗口文檔中創建的元素:
var div = printWindow.document.createElement('div');
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.