[英]Remove a node from the newly opened window jquery
我正在嘗試使用以下代碼打開一個新窗口。
$("#printBtn").on("click", function () {
var w = window.open(this.href, "myWindowName", "width=800, height=600");
$(w.document.body).children(".top-fixed-nav").remove();
return false;
});
我遇到的問題是新窗口的確打開了所需的輸出,但是我正在使用的行$(w.document.body).children(".top-fixed-nav").remove();
無法正常工作,即.top-fixed-nav
無法刪除。 我也嘗試將其綁定到ready
事件
$("#printBtn").on("click", function () {
var w = window.open(this.href, "myWindowName", "width=800, height=600");
$(w).ready(function(){
$(w.document.body).children(".top-fixed-nav").remove();
});
return false;
});
但這也不起作用。 誰能告訴我,我在做什么錯?
更新
嘗試過這個:
$("#printBtn").on("click", function () {
var w = window.open(this.href, "myWindowName", "width=800, height=600");
// $(w.document).ready(function(){
// and $(w.document).load(function(){
$(w.document.body).children(".top-fixed-nav").remove();
});
return false;
});
這兩個都不起作用。
$("#printBtn").on("click", function () {
var w = window.open(this.href, "myWindowName", "width=800, height=600");
$(w).on("load", function(){
$(w.document.body).children(".top-fixed-nav").remove();
});
return false;
});
嘗試一下此方法,因為onload方法可用於窗口而不是文檔。
嘗試綁定以加載而不是准備就緒:
$("#printBtn").on("click", function () {
var w = window.open(this.href, "myWindowName", "width=800, height=600");
$(w.document).on("load", function(){
$(w.document.body).children(".top-fixed-nav").remove();
});
return false;
});
經過一番擺弄后,arround得到了這個:
$("#printBtn").on("click", function () {
var w = window.open(this.href, "myWindowName", "width=800, height=600");
var callInterval = setInterval(childCall, 100);
function childCall(){
if (typeof w.jQuery !== "undefined") {
//w.jQuery(document.body).children(".top-fixed-nav").remove();
w.jQuery(".top-fixed-nav").remove();
if(typeof callInterval !== "undefined")
window.clearInterval(callInterval);
}
};
return false;
});
試試看,讓我們知道它是否有效:D
您可以嘗試以下方法:
var w = window.open(this.href, "myWindowName", "width=800, height=600");
w.document.$('body').children(".top-fixed-nav").remove();
或者:
$(".top-fixed-nav", w.document.body).remove();
注意 :您可能需要引入延遲才能允許加載窗口。
setTimeout('$(".top-fixed-nav", w.document.body).remove()', 5000);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.