2011-02-10 46 views
3

我正在處理一個老開發者的網站和代碼。刪除親子表格子窗口

有一個GLOBAL打印功能,傢伙寫道,基本上感覺到任何打開的新窗口(從任何方法)和「href.match」es域名...該腳本然後應用打印樣式表,如果需要並激發window.print。

這一切都是從每個頁面上的全局腳本完成的,幷包含一些其他功能。

我厭倦了寫每個頁面的案例添加,我想逃避這個功能。另外,如果我爲某個頁面編寫NOT子句,則在子窗口中的域內打開的任何後續頁面都將接收該打印函數。

有沒有辦法在這個新窗口中「繼續」繼承?基本上使這個窗口不是產生它的父親的孩子?

addEvent(window, 'load', function() { 
    var printBtn = document.getElementById('print-page'); 
    if (window.opener && window.opener.location.href.match('domainnamehere')) { 
     var printCSS = document.createElement('link'); 
     var a = document.getElementsByTagName('a'); 
     printCSS.href = 'css/print.css' 
     printCSS.setAttribute('type', 'text/css'); 
     printCSS.setAttribute('rel', 'stylesheet'); 
     document.getElementsByTagName('head')[0].appendChild(printCSS); 

     for (var i = 0; i < a.length; i++) { 
      a[i].href=""; 
      a[i].onclick = function() { return false; }; 
      a[i].style.cursor = "default"; 
     } 

     window.print(); 
    } else if (printBtn){ 
     printBtn.onclick = function() { 
      var printWindow = window.open(window.location, 'printwindow', 'resizable,width=800,height=800,scrollbars'); 

      return false; 
     }; 
    } 
}); 

回答

5

opener屬性是什麼讓進入子窗口,所以如果你想斷開所有你所要做的就是將其設置爲null。做這件事時,我總是把它複製到另一個屬性的情況下,抵消之前你需要其他別的原因......

if(bustInheritance) { 
    window.oldOpener = window.opener; 
    window.opener = null; 
} 
+0

感謝約什...完善。 – 2011-02-10 20:41:39

1

哈克,但可能做的伎倆:

var win_onload = window.onload; 
// replace it with a function that does nothing 
window.onload = function() { }; 

... open your window ... 

// put the event handler back 
wndow.onload = win_onload; 
+0

酷克里斯,但喬希先到那裏:)謝謝! – 2011-02-10 20:41:21