2011-04-22 97 views

回答

8

window沒有beforeload事件。

像這樣的東西可以工作,但請記住,覆蓋window.open是非常危險的。

var windowOpen = window.open; 

window.open = function(url, name, features, replace) { 
    alert("opening a window"); 
    // do other stuff here 
    windowOpen(url, name, features, replace); 
} 

window.open("http://www.google.com"); 
+0

你能否詳細說明覆蓋window.open()的壞結果? – uowzd01 2014-09-22 06:39:38

+1

覆蓋窗口(或大多數全局函數)通常是一個糟糕的主意,因爲重寫的實現可能更容易出錯,並且可能對依賴於window.open的其他代碼產生意想不到的副作用。 一個更好的策略通常是提供一個新的函數,調用window.open並做一些你想要window.open去做的事情,並在你自己的代碼中使用它。這樣,只有調用您的方法的代碼纔會受到影響。 – ktusznio 2014-09-22 22:21:58

相關問題