Jump to content
lilmer

On close browser.

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?

Share this post


Link to post
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.

Share this post


Link to post
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.

Share this post


Link to post
Share on other sites

I would comment on what the OP is wanting to implement. But, then I would have to ban myself for language.

Share this post


Link to post
Share on other sites

Nope, its not a usual page ads thats keeps on triggering every time you exit a site. This is for specific user and by user level, and once you agree to terms it will not pop again.

Share this post


Link to post
Share on other sites

Literally the only thing I have ever seen popup when I try to close my tab/browser or otherwise navigate from the page that I only _marginally_ consider "okay" (read: barely tolerable) is a warning about losing unsaved changes to something.  

Edited by .josh
  • Like 1

Share this post


Link to post
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.

 

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

Share this post


Link to post
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.

Share this post


Link to post
Share on other sites

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.


×
×
  • 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.