SitePoint Sponsor

User Tag List

Results 1 to 9 of 9

Hybrid View

  1. #1
    SitePoint Addict
    Join Date
    May 2005
    Posts
    248
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    close a page with alert/message

    Hi all,
    Before the user can close a page, I would like to have a message come up that asks if this is really what they want to do. the page needs to stay open.
    I got this, edited, from msdn
    function closeIt()
    {
    event.returnValue = "";
    }
    <body onbeforeunload="closeIt()" >


    It works just fine, too well. I get the message when the user refreshes the page, something I do not want.
    Any thoughts?

    Also with the above, I don't like the alert message and would like to have it read differently. Suggestions on this...

    Many thanks

  2. #2
    SitePoint Guru
    Join Date
    Apr 2006
    Posts
    802
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Nobody likes an alert popping up when they are trying to navagate away from a webpage.

  3. #3
    SitePoint Addict
    Join Date
    May 2005
    Posts
    248
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi,
    maybe not the right way to have done it, but the opening page has data on it to which other pages refer. I need to keep that initial page open so that the user can transfer data from the secondary page to the opening page.

    any ideas?

    thanks

  4. #4
    SitePoint Guru
    Join Date
    Apr 2006
    Posts
    802
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Webpages are transient- Generally we save data on the server, in files or databases, uploaded from our pages.

    You can pass a couple kbs of data between pages in a cookie, or a hundred characters or so on the url, but how much data can you use that doesn't belong on the server, where any page you allow can access it?

  5. #5
    SitePoint Addict
    Join Date
    May 2005
    Posts
    248
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi
    yes, I agree, pages are transient
    and for among the various reasons listed above, this is what I'd like to do. The data does eventually end up on the server.
    so, all other issues aside... what is possible?
    thanks

  6. #6
    SitePoint Member gmn17's Avatar
    Join Date
    Jan 2004
    Location
    Los Angeles
    Posts
    15
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi
    yes, I agree, pages are transient
    and for among the various reasons listed above, this is what I'd like to do. The data does eventually end up on the server.
    so, all other issues aside... what is possible?
    thanks

    be a man/woman and tell the lamebrain idiots who need this feature that they suck at using a computer.

  7. #7
    SitePoint Member gmn17's Avatar
    Join Date
    Jan 2004
    Location
    Los Angeles
    Posts
    15
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ha ha...
    What is this?

    this type of feature is needed for moronic asses who do not back up their own work and every time I need to do my work, I have to click an idiot button to post. not funny at all.

  8. #8
    Programming Since 1978 silver trophybronze trophy felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, NSW, Australia
    Posts
    16,836
    Mentioned
    25 Post(s)
    Tagged
    1 Thread(s)
    You can use the proprietary onbeforeunload event handler to popup a confirm message in those browsers that support it but the only standard event that runs when a page is being unloaded is the onunload handler that doesn't run until after it is too late for them to change their minds.

    window.onbeforeunload = function() {return confirm('Ready to leave?');};
    window.onunload = function() {alert('bad luck if you forgot to backup');};
    Stephen J Chapman

    javascriptexample.net, Book Reviews, follow me on Twitter
    HTML Help, CSS Help, JavaScript Help, PHP/mySQL Help, blog
    <input name="html5" type="text" required pattern="^$">

  9. #9
    SitePoint Addict
    Join Date
    May 2005
    Posts
    248
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hello
    I do certainly understand all the user problems
    thank you felgall for your kind(er) answer
    I'll give it a try


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
  •