我在使用$ 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也用在此应用程序中,也许与我的问题有关。

在此先感谢您的帮助。

最佳答案

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();
}

关于javascript - jQuery-新窗口中的选择器,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/20224137/

10-11 23:32
查看更多