To avoid circular calls, you need to stash away the original window.open
function in a variable.
A nice way (that doesn't pollute the global namespace) is to use a closure. Pass the original window.open
function to an anonymous function as an argument (called open
below). This anonymous function is a factory for your hook function. Your hook function is permanently bound to the original window.open
function via the open
argument:
window.open = function (open) {
return function (url, name, features) {
// set name if missing here
name = name || "default_window_name";
return open.call(window, url, name, features);
};
}(window.open);
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…