SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Evangelist Mr. Tech's Avatar
    Join Date
    Feb 2003
    Location
    Australia
    Posts
    562
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    event.returnValue - how do I get it to work in FireFox?

    The following code works in IE... When someone tries to navigate away from a page without saving the changes, a message pops up...

    Code:
    window.onbeforeunload = cancelUnload;
    
    var bFireWarning = true;
    
    function cancelUnload()
    {
      if(bFireWarning == true)
    	  event.returnValue = "If you leave this page, all your changes will be lost!\nTo save your changes, click the 'Save Changes' button.";
    }
    On blogger.com, they also make this work in FireFox... Not sure if they use the same code or not but I can't figure it out... How do I make this code work in FireFox as well as IE?

  2. #2
    CSS & JS/DOM Adept bronze trophy
    Join Date
    Mar 2005
    Location
    USA
    Posts
    5,482
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    returnValue is part of IE5+/Win's event model -- other browsers don't support it.

    Try this:
    Code:
    function cancelUnload()
    {
      if(bFireWarning === true)
        return "If you leave this page, all your changes will be lost!\nTo save your changes, click the 'Save Changes' button.";
    }
    We miss you, Dan Schulz.
    Learn CSS. | X/HTML Validator | CSS validator
    Dynamic Site Solutions
    Code for Firefox, Chrome, Safari, & Opera, then add fixes for IE, not vice versa.


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
  •