SitePoint Sponsor

User Tag List

Results 1 to 13 of 13

Hybrid View

  1. #1
    SitePoint Member
    Join Date
    Jul 2002
    Posts
    13
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Popup window on site exit

    Hi,

    Does anyone know how to make a popup window appear when a site is left or the browser is closed?

    I've tried using the unLoad() method, but that pops up a window when each site page is left, rather than when the doamin is left.

    Anyone have any ideas?

    Andy

  2. #2
    Currently Occupied; Till Sunda Andrew-J2000's Avatar
    Join Date
    Aug 2001
    Location
    London
    Posts
    2,475
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    in the body tag put

    onunload="popup()"


    and in the head put this

    Code:
    <script type="text/javascript">
    <!--
    
      function popup(url, w, h) //w = width, h = height
      {
        win = window.open(url, 'popup', '');
      }
    
    // -->
    </script>
    try that

  3. #3
    Web-coding NINJA! silver trophy beetle's Avatar
    Join Date
    Jul 2002
    Location
    Dallas, TX
    Posts
    2,900
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I've only seen that done with frames pages, and the onUnoad() event is put on the body of the frameset...which basically gets what you want...only fires when domain changes or browser closes.

    I suppose if you don't need frames, you could just make a 1-frame framset.
    beetle a.k.a. Peter Bailey
    blogs: php | prophp | security | design | zen | software
    refs: dhtml | gecko | prototype | phpdocs | unicode | charsets
    tools: ide | ftp | regex | ffdev




  4. #4
    SitePoint Member
    Join Date
    Jul 2002
    Posts
    13
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks for the suggestion Andrew, but onUnload pops up the window when a page is left, not when the site is left (so the window will appear even if the visitor goes to another page in the same site).

    Beetle - I'm afraid frames are a no-no too (search engines don't like 'em!)

    Thanks anyway guys.

  5. #5
    Web-coding NINJA! silver trophy beetle's Avatar
    Join Date
    Jul 2002
    Location
    Dallas, TX
    Posts
    2,900
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I've made some js that'll help you with frames/search engine friendliness. You may want to use it. Documentation is in the .js file

    http://www.peterbailey.net/js/superframes.js

    Enjoy.
    beetle a.k.a. Peter Bailey
    blogs: php | prophp | security | design | zen | software
    refs: dhtml | gecko | prototype | phpdocs | unicode | charsets
    tools: ide | ftp | regex | ffdev




  6. #6
    Currently Occupied; Till Sunda Andrew-J2000's Avatar
    Join Date
    Aug 2001
    Location
    London
    Posts
    2,475
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    oh try the top parent then. As theys the one i would have thought you would have put it. I never work with frames normally and that seems the right place for it.

  7. #7
    SitePoint Member
    Join Date
    Jul 2002
    Posts
    13
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Many thanks for the .js, beetle. I'll give it some thorough reading!

  8. #8
    Web-coding NINJA! silver trophy beetle's Avatar
    Join Date
    Jul 2002
    Location
    Dallas, TX
    Posts
    2,900
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You bet...let me know what you think after you get through it....I'd like to know if some of the crap I code up for myself is acutally useful to others!
    beetle a.k.a. Peter Bailey
    blogs: php | prophp | security | design | zen | software
    refs: dhtml | gecko | prototype | phpdocs | unicode | charsets
    tools: ide | ftp | regex | ffdev




  9. #9
    Perl/Mason Guru Flawless_koder's Avatar
    Join Date
    Feb 2002
    Location
    Gatwick, UK
    Posts
    1,206
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You need to check the next url isn't the same url as your url.

    Otherwise you'll be popping that window up on refresh - since that does count as an unload.

    Flawless
    ---=| If you're going to buy a pet - get a Shetland Giraffe |=---

  10. #10
    SitePoint Member
    Join Date
    Jul 2002
    Posts
    13
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks, Flawless_Koder. Do you happen to know the method of checking the next URL isn't the same as your URL?

  11. #11
    Perl/Mason Guru Flawless_koder's Avatar
    Join Date
    Feb 2002
    Location
    Gatwick, UK
    Posts
    1,206
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I'm afraid not

    If i could remember i would have posted it straight away.

    I'm fairly sure it's part of the properties - you can look at them on
    msdn.microsoft.com/library

    Flawless
    ---=| If you're going to buy a pet - get a Shetland Giraffe |=---

  12. #12
    SitePoint Member
    Join Date
    May 2002
    Posts
    12
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hello,

    I wish to do the same.

    I came across some code that may work:

    Code:
    <SCRIPT LANGUAGE="JavaScript">
    <!--
    var clicked=0;
    var win = 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=no,width=300,height=300,left=1,top=1';
    function console() {
    if (clicked==0) {
    if (document.domain.search(".com")!=-1) {
    
    window.open('whatever.htm','whatever',win)
    }
    }}
    </script>
    However, this code will require that I add

    Code:
    onclick="clicked=1"
    to all links on my site that point to my site. Any other links, particularly those that leave my site, will produce the popup.

    But this wouldn't control for someone typing in a new domain in the browser (or clicking on a bookmark directly from the browser application). And it also wouldn't control for when the user closes the browser down altogether.

    Does anyone have any other suggestions?

    Thank you.

  13. #13
    SitePoint Zealot LunaC's Avatar
    Join Date
    Feb 2001
    Posts
    176
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I haven't tried this one yet, but look at the third script down on This page

    It looks like it should work.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •