Unblock window.open pop-up?
Due to the limitations of a really clunky CMS, I am unable to use
target="_blank"
to open links in new windows. So I'm thinking that my only real solution is to point the link at an intermediary page that opens a new window and then 开发者_Go百科redirects the current window back to the originating page... so something like this:
window.open ("http://www.NewPage.com/");
window.location = "http://www.OldPage.com/";
Of course, most browsers will block the window.open method... so what are my options? Surely there's some clever Javascript trickery to get around this.
No options. You can't do it, and for good reason.
Browsers will only allow window.open()
to work when the code that calls it is handling an event like "click". In that circumstance, the browser assumes that the page provides a clickable element and that the user knows there'll be a popup. If a page just calls window.open()
for a new window from some context like straight script code, or in a "ready" or "load" event handler, or an XMLHttpRequest callback, then the browser assumes the popup may be something obnoxious.
Some browsers allow the user to relax those rules, but your code can't force that.
You can probably just inject an iframe on the page and position it over everything, but I would really not recommend this.
The browser will be in control of whether the window.open
is allowed or not at the end of the day so I wouldn't bother trying to find a solution.
精彩评论