Jump to content

On close browser.


lilmer
 Share

Recommended Posts

Hello, I want to add a process that will trigger a show of advertisement or opening a new tab when the user close a the tab or browser. 

$(window).bind("beforeunload", function(e) {

    window.open(URL+'ads', '_blank');

    return 'You are closing the browser';

});

The window.open and the return message is both not working. I tried also other possibilities but window.open is not working. Anyone knows about this?

Link to comment
Share on other sites

What you want to do is despicable.

 

Are you saying the onbeforeunload works but the window.open does not? If it's not a problem with the code itself (eg, "URL" undefined or invalid) then it's likely that the browser is deliberately preventing that from happening.

Link to comment
Share on other sites

What you want to do is despicable.

 

I couldn't agree more.

 

Aggressive ads are already the cancer of the Internet, but popping up a new window when I want to close the current one makes me want to punch the developer in the face.

 

Seriously, stop it. Even if you manage to get your code past the browser's malware filter, your users will be truly annoyed and either turn their ad blocker all the way up or leave your site forever. It's just counter-productive.

Link to comment
Share on other sites

  • 2 weeks later...
  • 3 weeks later...

^^ Actually I find the pop-up quite useful if I am writing something and accidentally click the close button on a tab or browser (pls don't hate me, lol) especially if there is no auto safe.

 

As for the op, it is not possible to write to add a custom message onbeforeunload or any event that is triggered when the user wants to leave. You can add some text (on few browsers) additionally to the default message and that's it. Browsers do that for defense.

Edited by Stefany93
Link to comment
Share on other sites

^^ Actually I find the pop-up quite useful if I am writing something and accidentally click the close button on a tab or browser (pls don't hate me, lol) especially if there is no auto safe.

 

This is acceptable if I have coded an application that a user is working in and wants to leave an area without saving.

 

But as a 'WAIT DON'T LEAVE!' for a webpage, I make a point to not go back to that site again, report it, etc.

Link to comment
Share on other sites

This thread is more than a year old.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.