2012-07-13 134 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