Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.
Hi all, please see this major site announcement: https://www.boards.ie/discussion/2058427594/boards-ie-2026

site exit popup

  • 03-07-2007 08:06AM
    #1
    Registered Users, Registered Users 2 Posts: 648 ✭✭✭


    hi
    i found this script that creates a popup on exit of the page
    http://www.nowsell.com/pop-ups/exit-popup-scripts.html

    however i need to create popup on exit of the site and not each and every page

    does anyone know how to do this ?

    tnx


Comments

  • Closed Accounts Posts: 4,655 ✭✭✭Ph3n0m


    Are you talking about when the user clicks a link to leave the site, or closes the browser or types a new url in the address bar?


  • Registered Users, Registered Users 2 Posts: 648 ✭✭✭ChicoMendez


    Ph3n0m wrote:
    Are you talking about when the user clicks a link to leave the site, or closes the browser or types a new url in the address bar?

    good question - either/any of the above
    ideally a solution that would capture any of the above (but i dont think its possible to detect the latter??)

    closing the browser window might be only one we can detect (correct me if im wrong) ?

    tnx


  • Closed Accounts Posts: 4,655 ✭✭✭Ph3n0m


    http://www.hasbro.com/transformers/en%5FGB/ - bottom left side, the "official movie site" link is a pop up exit script, that should prove useful

    However its only for exit links from a site - you could also try and combine the popup function with an onclose method

    This also might help aswell - http://www.geocities.com/z0z0z02003/leave.htm

    However if people have popup blocker activated - this makes it kind of redundant


  • Registered Users, Registered Users 2 Posts: 872 ✭✭✭grahamor


    There is a method called onBeforeUnload that fires when the page is closed.

    Check out this link, you get an alert when you close the browser tab

    http://www.4guysfromrolla.com/demos/OnBeforeUnloadDemo1.htm


  • Closed Accounts Posts: 18,152 ✭✭✭✭Liam Byrne


    onBeforeUnload is IE and FF only

    Assuming that internal links are relative (i.e. that you can distinguish external ones by checking for http:// at the start), you can do this using jQuery:

    <script type="text/javascript" src="jquery/jquery.js"></script>
    <script type="text/javascript">
    function yourUnloadAlert(internalLink) {
    $(window).unbind("unload");
    if (internalLink==true) {
    return;
    }
    alert("this should trigger for external links and window.unloads");
    }

    $(document).ready(function() {
    $(window).one("unload", function() {
    yourUnloadAlert(false);
    });

    $("a").each(function() {
    linkURL=$(this).attr("href");
    if (linkURL.indexOf("http://")==-1) {
    $(this).click(function() {
    yourUnloadAlert(true);
    });
    };
    });
    });
    </script>


  • Advertisement
  • Registered Users, Registered Users 2 Posts: 648 ✭✭✭ChicoMendez


    liam,

    that sounds like a nice solution
    however im getting je error:

    Error: $(window).one is not a function

    tnx


  • Closed Accounts Posts: 18,152 ✭✭✭✭Liam Byrne


    Did you download and link to jQuery ?

    http://code.google.com/p/jqueryjs/downloads/detail?name=jquery-1.1.3.pack.js

    Sample page with the above script working

    http://www.onsight.ie/test.html


  • Registered Users, Registered Users 2 Posts: 648 ✭✭✭ChicoMendez


    yes i had downloaded jquery

    however one issue is that im using a CMS that generates the urls (so all the urls have http://www. even the 'relative ones)
    hmmmmm


  • Closed Accounts Posts: 18,152 ✭✭✭✭Liam Byrne


    Then reverse the "http://&quot; indexOf comparison and use the name of the current server (e.g. "http://www.yourserver.com")

    :
    if (linkURL.indexOf("http://www.yourserver.com")==0) {
    :

    Did you manage to get jQuery working ?


Advertisement
Advertisement