Pregunta

i want to open a popup window when user leaves tab or closes browser, the available option with me was window.open, but with that, it asks for popup blocker, if it is not enabled, i tried every possible ways to ignore popup-blocker but in vain, i tried onunload, onbeforeunload, but it does not works, i also tried to use modal dialog, before the tab/browser, i used it in onbeforeunload event, but it shows a browsers alert message, which i dont want, my simple requirement is, i need a popup window (if possible) or modal dialog, on the close of tab/browser, but should ignore popup-blocker, i guess with modal dialog, i dont need to worry about popup-blocker, because that wont be the new window, but how i would be handling it, while user closes tab/browser. If any of the above option is not possible, can anyone help me with any other possible alternative, or helpful articles.

Edited Question
i used the below script and with that i can open a new popup window on link click, without popup-blocker interfering in it

$('a[href=http://www.google.com]').click(function(){
    window.open(this.href);
    return false;
  });

then why its not possible for the closing events.

¿Fue útil?

Solución

You can't - because that's what popup blockers do: they block popup windows (i.e. calls to window.open or invocations of target="_blank" links) unless it is directly in response to a user mouse action.

Opening popups when a browser window is closed was a common tactic of "pop-under" ads in the early 2000s, and it irritated users, that's why Firefox and IE6's popup blocker block them, and there is no way around it for you unless you ask the user to disable their popup blocker on your site (and I think you'll find most of them will have no idea how to do that).

What are you trying to accomplish anyway? What is the content of this popup that you want the user to see? What other approaches have you tried?

Otros consejos

Exact duplicate of your previous question....

I'll post my answer for it here as well though...

Popup blockers are designed to prevent this behavior.

I would suggest using a modal window instead of an actual browser window. I don't think that these get blocked because they are opened within the page itself.

As for the event... You could do something like...

window.onbeforeunload = function whatever() {
       //Do code here for your modal to show up.
 }

If you are just trying ot give a warning or something you could do

window.onbeforeunload = function showWarning() {
       returnString = 'Whatever you want your message to be....';
       return returnString;
 }

By returning something in the onbeforeunload statement it will show a confirm box with your message in it.

Popup blocker will not block the opening of popups if the javascript code which opens the popup is executed on user's direct action like click, keypress, drag, etc.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top