I'm looking for javascript code that will open popuner window with URL (web page in it) when visitor open my site (on load) or on exit.
I want something that will pass firefox and all other popup blockers.
| SitePoint Sponsor |
I'm looking for javascript code that will open popuner window with URL (web page in it) when visitor open my site (on load) or on exit.
I want something that will pass firefox and all other popup blockers.

There is nothing that can bypass the blockers as the blockers are specifically designed to block windows opening in those situations.
The only way to bypass the blockers is to open the new window when your visitor clicks a link.
The only other way to do it is as a popin within the web page itself.
Stephen J Chapman
javascriptexample.net, Book Reviews, follow me on Twitter
HTML Help, CSS Help, JavaScript Help, PHP/mySQL Help, blog
<input name="html5" type="text" required pattern="^$">
So, how to "open the new window when your visitor clicks a link."


By attaching a function to the link's onclick event from where you could use window.open using the alwaysLowered setting to put the new window behind the current one.
Programming Group Advisor
Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
Car is to Carpet as Java is to JavaScript
This will open in a new window.HTML Code:<a href="www.google.com" target="_blank">LINK</a>
EDIT:
Unless you want it always behind, in which case Paul's got it right.By attaching a function to the link's onclick event from where you could use window.open using the alwaysLowered setting to put the new window behind the current one.

But should not be used because:
1. target is deprecated and ceased to be a proper part of HTML back in 1997.
2. Opening a new window is a behaviour and so should be done using JavaScript and not HTML.
The correct code for such a link (but jumbling the JavaScript with the HTML to make the comparison more obvious - rather than doing it properly with separate files the way you'd do it for a proper web page) is:
Of course since blur (and focus) are non-standard for windows it will depend on which browser your visitor is using as to which window will end up on top.HTML Code:<a href="www.google.com" onclick="newwin window.open(this.href);newwin.blur();">LINK</a>
Stephen J Chapman
javascriptexample.net, Book Reviews, follow me on Twitter
HTML Help, CSS Help, JavaScript Help, PHP/mySQL Help, blog
<input name="html5" type="text" required pattern="^$">
Bookmarks