Displaying text before a user navigates from a page

Discussion in 'JavaScript' started by organicCyborg, Dec 3, 2009.

  1. #1
    I think this is possible with Javascript, but I'm not familiar enough with the language to be sure.

    Basically, whenever the user closes the browser window/tab or navigates away from the page I'd like some text and maybe in image to fade in (using jQuery) and then the window/tab would be closed, or the user would be taken to their desired page.

    I feel like this should be possible, but I fear it isn't because it would be so easy to exploit.
     
    organicCyborg, Dec 3, 2009 IP
  2. camjohnson95

    camjohnson95 Active Member

    Messages:
    737
    Likes Received:
    17
    Best Answers:
    0
    Trophy Points:
    60
    #2
    
    window.onbeforeunload = function() {
    	alert("MESSAGE");
    }
    
    Code (markup):
    But I don't think that there is a way to display something on the page and delay the exit any other way... You could display a popup on exit, but most browsers would block it anyway, and it would just annoy anyone who did see it.
     
    camjohnson95, Dec 3, 2009 IP