I'm trying to override window.open()
, so I'm trying to find a way to open link in new window without window.open()
.
In detail, I'm in such a situation: I've got a Silverlight Web Part Which uses HTMLWindow.Navigate()
to open hyperlinks in new window, so I cannot use <a>
because I've got totally no control to the Web part. The only way is to override window.open()
.
For example, when I want to open link in the top window, I override window.open()
like this:
window.open = function (open) {
return function (url, name, features) {
window.top.location = url;
return false;
};
}(window.open);
Is there a similar method to open link in new window? Thank you very much!
PS: I cannot use anchor here because I'm overriding window.open()
What I did finally for this problem:
Firstly, I made a copy of window.open()
var _open = window.open;
Then I override the window.open()
function. Supposing that "target" is a variable that receives querystring, for example. Note that the default behavior is to open the link in the current window.
if (target == "top")
{
window.open = function (open) {
return function (url, name, features) {
window.top.location = url;
return false;
};
}(window.open);
}
else if (target == "blank")
{
window.open = function (open) {
return function (url, name, features) {
return open_(url, '_blank', features);
};
}(window.open);
}
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…