2012-07-13 92 views
2

如何打开窗口并在该窗口中选择对象?

newWindow=window.open(document.URL); 
$('div#header',newWindow.document).hide(); 
$('div#footer',newWindow.document).hide(); 

但它似乎并不奏效。有任何想法吗?

+0

相同document.domain的下运行的新窗口? – jbabey 2012-07-13 17:54:09

+0

@jbabey,新窗口加载'document.URL'。 – 2012-07-13 17:54:47

+2

不幸的是,jQuery的'.ready'函数只能在当前窗口的上下文中使用,因此您必须在新窗口上等待'.load'或创建您自己的'.ready'实现,该实现可以跨越窗口上下文。 – zzzzBov 2012-07-13 18:02:54

回答

2

试试这个:

newWindow = window.open(document.URL); 
$(newWindow).load(function() { 
    $('#header', newWindow.document).hide(); 
    $('#footer', newWindow.document).hide(); 
}); 
+0

对于那些想要测试的人,请在此页面上按Ctrl + Shift + j(谷歌浏览器)并复制粘贴。你应该得到这个页面没有页脚和标头 – Esailija 2012-07-13 18:16:31

+0

+1为优秀的工作。 – Adil 2012-07-14 04:25:54