1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

PHP Help Please: Popup When Visitor Exits Website?

Discussion in 'PHP & Perl' started by muchacho, Oct 17, 2009.

  1. muchacho

    muchacho Supreme Member

    Joined:
    May 14, 2009
    Messages:
    1,293
    Likes Received:
    187
    Location:
    Lancashire, England.
    I'm after some php code that will result in the visitor getting a pop up when they actually leave the website.

    I don't want it to pop up if they leave the webpage, for another on the same domain.

    Is this possible and with all the popup blockers nowadays, is it worth it or do most people have software that will stop them?
     
  2. iPwnJ00

    iPwnJ00 Junior Member

    Joined:
    Mar 10, 2009
    Messages:
    132
    Likes Received:
    21
    Location:
    Melbourne, Australia
    Lol... That's not PHP, that's Javascript.
     
  3. windofchange

    windofchange Registered Member

    Joined:
    Jan 31, 2009
    Messages:
    53
    Likes Received:
    11
    Script To Open An Exit Window When Someone Leaves Your Site:

    Place the following script between the <HEAD> and </HEAD> tags:
    <script language="javascript">
    <!-- begin

    var exit=true;
    function exitwindow()
    {
    var url = 'URL/to/popup.html';
    var win = 'toolbar=0,directories=0,menubar=0,scrollbars=0,
    resizable=0,width=250,height=300';
    if (exit)
    open(url,'WindowName',win); }

    // end -->
    </script>




    Add the following into your <BODY> tag:
    onUnload="exitwindow()"
    Your <BODY> tag should then look something like this:
    <BODY bgcolor="#ffffff" text="#000000" onUnload="exitwindow()">




    And add the following into all internal links where you DO NOT want the new window to open:
    onclick="exit=false"
    For example:
    <A href="http://www.nowsell.com/order.html" onclick="exit=false">Order Now</A>




    Although the script above is designed specifically to create an exit pop-up, you can in fact quite easily turn a standard on-entry pop-up into an exit pop-up.
    How?
    Simply change the onLoad command in the <BODY> tag to onUnload. You will still have to insert the onclick="exit=false" code into the links you don't want to trigger the pop-up.


    Script To Pre-Load Your Exit Window:

    This code will load your exit window information into the browser at the same as the main page. This makes it appear much faster when triggered by the visitor leaving the page.

    Place the following below the <BODY> tag:
    <iframe src="URL/to/popup.html" name="FunctionName" height="0" width="0" noresize></iframe>
    For Example, using the exit pop-up above:
    <BODY bgcolor="#ffffff" text="#000000" onUnload="exitwindow()">
    <iframe src="http://www.NowSell.com/popup.html" name="exitwindow" height="0" width="0" noresize></iframe>
     
    • Thanks Thanks x 1
  4. SpiderWebMaster

    SpiderWebMaster Power Member

    Joined:
    Jan 24, 2009
    Messages:
    617
    Likes Received:
    519
    Occupation:
    I don't have a job...
    Location:
    /dev/null
    i see that you are pretty good with popups, so, any way to make one pop when somebody clicks the page? even if they don't leave the page, kinda like what mediafire does, you click the page you see a popup. if there was a way to make it open a layer on top of the page it would be great,
    maybe it's me who's dumb, cause i already looked into many popup/popunder codes and i am yet to find one like that, no matter what i try, in fact most of them just mess my pages :(
     
  5. ericsson

    ericsson Elite Member Premium Member

    Joined:
    Apr 25, 2009
    Messages:
    2,642
    Likes Received:
    8,132
    Occupation:
    www
    Location:
    Swe
    Home Page:

    Im bump this .. ;)

    //J
     
  6. cyberfox

    cyberfox BANNED BANNED

    Joined:
    Dec 29, 2009
    Messages:
    54
    Likes Received:
    2
    You can make a click event on the document , and when the user clicks on any area within the page , the pop up opens ,
    no popup-blocker will block this , since the window is opened as a result of a user click , not automatically
     
  7. cyberfox

    cyberfox BANNED BANNED

    Joined:
    Dec 29, 2009
    Messages:
    54
    Likes Received:
    2
    and this is a javascript issue , so , please move this dialogue to the proper section...!!