jQuery - 在新窗口中选择元素

3

我在使用$window.open()打开的新窗口中不能访问元素:

var printWindow = window.open(window.location.href, 'Imprimer', config = 'width=1024, toolbar=no, menubar=no, scrollbars=yes, resizable=yes, location=no, directories=no, status=no');

printWindow.onload = function() {
    printWindow.find(".navbar").remove();
}

这里,printWindow.find(".navbar").remove();这行代码不起作用。我试了几个jQuery选择器,但没法访问我的弹出框中的".navbar"。
顺便提一下,这个应用程序也使用了AngularJS,也许与我的问题有关。
非常感谢您的帮助。

".navbar" 定义在哪里? - Sterling Archer
顺便问一下,$window是什么?你是不是想说window呢? - A. Wolff
@RUJordan。.navbar在我的页面中定义,我正在尝试使用window.open(window.location.href)在新窗口中重新打开当前页面。 - 11OClock
@A.Wolff 是的,我是指窗口。 - 11OClock
2个回答

0

printWindow没有find()方法,它不是jQuery集合吗?

var printWindow = $window.open(window.location.href, 'Imprimer', config = 'width=1024, toolbar=no, menubar=no, scrollbars=yes, resizable=yes, location=no, directories=no, status=no');

printWindow.onload = function() {
    $(printWindow.document.body).find(".navbar").remove();
}

我已经尝试过了,但似乎不起作用:我的导航栏元素没有被移除,而且我找不到页面上的任何元素。此外,在JS控制台中也没有错误消息。 - 11OClock

0

你需要将printWindow转换为jQuery对象。

$(printWindow.document).find(".navbar").remove();

我已经尝试过了,但似乎不起作用:我的导航栏元素没有被移除,而且我找不到页面上的任何元素。此外,在JS控制台中也没有出现任何错误消息。 - 11OClock
@11点整,请确保您遵循“同源策略”的规则,并从此处阅读其他详细信息。 - Fredrick Gauss

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接