SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Member
    Join Date
    Dec 2004
    Location
    bham
    Posts
    2
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question Firefox onbeforeunload woes -- simple script

    I have a function that should just alert the user that they are leaving the site by by closing the browser window. It works fine in IE but not in FireFox 1.0 Perhaps you could help?

    Code:
    <script language="javascript">
         function Logout() {
    								if (event.clientY < 0)
                 {
    	    alert("Hey");
    	}
    }
    </script>
    
    <body onbeforeunload="Logout()">
    Thanks

  2. #2
    SitePoint Wizard
    Join Date
    Nov 2004
    Location
    Portsmouth UK
    Posts
    1,498
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It worjks in FF if

    PHP Code:

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
        "http://www.w3.org/TR/html4/strict.dtd"
    >

    <
    html>

    <
    head>
      <
    title></title>
    </
    head>
    <
    script language="javascript">
    function 
    Logout(e) {
    // if (event.clientY < 0) {
      
    alert("Hey");
    // }
    }
    </script>

    <body onbeforeunload="Logout()">
    </body>

    </html> 

    event.clientY is IE try e.pageY for FF, NS etc

    but its not reqd in this instant

    Does Not work in NS though

  3. #3
    SitePoint Member
    Join Date
    Dec 2004
    Location
    bham
    Posts
    2
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Great job! Now it works on any refresh/close of the browser. Now I would like the alert to happen only if they close the browser window via the X at the top right of the window. I've tried testing for event.pageY <= 0 and e.pageY <= 0 and both do not work. Perhaps you know a workaround?

    Oh yea, why is there an e argument in my Logout function now?


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
  •