jQuery - 新窗口上的选择器

时间:2013-11-26 17:38:03

标签: javascript jquery

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

提前感谢您的帮助。

2 个答案:

答案 0 :(得分: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();
}

答案 1 :(得分:0)

你必须使printWindow成为一个jQuery对象。

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