使用javascript捕获新的浏览器窗口打开事件
答
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");
你能否详细说明覆盖window.open()的坏结果? – uowzd01 2014-09-22 06:39:38
覆盖窗口(或大多数全局函数)通常是一个糟糕的主意,因为重写的实现可能更容易出错,并且可能对依赖于window.open的其他代码产生意想不到的副作用。 一个更好的策略通常是提供一个新的函数,调用window.open并做一些你想要window.open去做的事情,并在你自己的代码中使用它。这样,只有调用您的方法的代码才会受到影响。 – ktusznio 2014-09-22 22:21:58