browser alert about open / popup new window
I have a link that when clicked, the browser will open a new window. This the code for the click event on that link:
var clickView = function(){
window.open('/client/item/show/' + itemID);
return false;
};
I also have another function that, read the url from a ajax call and open it in a new window.
if (json.data && json.data.URL)
{
if (me.urlTarget==='_self'){
//use the self window to open the URL
window.location.href =json.data.URL;
} else{
//use new window to open the url.
window.open(json.data.URL);
}
}
For the first function (clickView), the browser (IE7/8 & Firefox) wil开发者_Go百科l open a new tab without any warning to user. For the second function (where the url is read from json.data.URL), both IE and Firefox will show an warning message and block the new window until the user agree on the warning. In both functions the opening URL is the same.
I'm wondering why is there a difference, and is it possible to make them behave consistent?
The answer appears to be here: open new window without the browser giving warning that is a popup
Summary: calling window.open() at seemingly random times causes the browser to kick in with a warning/prompt. Calling window.open() as a result of a link click works fine.
Possibly the second instance generates a warning because it is an absolute, rather than relative URL?
(Either way, opening new browser windows is the devil's work).
精彩评论