Page 1 of 2 12 LastLast
Results 1 to 10 of 11

Thread: Is there a script for confirming site exist with an alert box?

  1. #1
    Join Date
    Oct 2004
    Posts
    79
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Lightbulb Is there a script for confirming site exist with an alert box?

    Is there a script for confirng site exist with an alert?
    I want something that says yes or cancel (or similar) in a alert message before leaving the site. but usually using "confirm" and pressing cancel button does the same as the yes button (leaves the site).

    <HTML>
    <HEAD>
    <SCRIPT>
    function closeIt()
    {
    event.returnValue = "Any string value here forces a dialog box to \
    appear before closing the window.";
    }
    </SCRIPT>
    </HEAD>
    <BODY onbeforeunload="closeIt()">
    <a href="">Click here to navigate to</a>
    </BODY>
    </HTML>


    this actually works out, but I don't want the extra text. is there a way to get this effect without the extra text? just my text, and confirm box working?

  2. #2
    Join Date
    Aug 2004
    Posts
    10,143
    Thanks
    3
    Thanked 1,008 Times in 993 Posts
    Blog Entries
    16

    Default

    Trust me, it's really not a good idea to use prompt boxes in this way, as most users will really find it annoying. Unfortunately you can't remove that default message that pops up, as it's part of IE's security measures to always give the ultimate choice to the user. It's similar to when you try and close the main window using JavaScript- an alert message pops up.

  3. #3
    Join Date
    Oct 2004
    Posts
    79
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    yes... I know that...
    the ideia is nto annoying... I was surprised people liking it (it gives info about time spent). yet, I don't ask to change the alert in itself... but the alert type. instead of just ok button. have ok and cancel too.
    the confirm value instead of "event.returnValue " does the trick but does not work well for quitting windows...because cancel makes it quit too... how do I solve this?

  4. #4
    Join Date
    Aug 2004
    Posts
    10,143
    Thanks
    3
    Thanked 1,008 Times in 993 Posts
    Blog Entries
    16

    Default

    Hmm I'm confused- "quiting windows?" Can you explain what exactly you're trying to do with a confirm box? Obviously you can't give people a choice between quiting Windows or not using JavaScript.

  5. #5
    Join Date
    Aug 2004
    Location
    Brighton
    Posts
    1,563
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    We could try modifying this script if this is what you mean...

    http://javascript.internet.com/messa...o-confirm.html

    cr3ative
    A retired member, drop me a line through my site if you'd like to find me!
    cr3ative media | read the stickies

  6. #6
    Join Date
    Oct 2004
    Posts
    79
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    yes! indeed that is the type of alert box... just want that for exiting the page... the box could also have configurable text... and when ok is pressed, one leaves... when cancel is pressed, one stays (also an alert message could appear as an option).


    thanx for the attention

  7. #7
    Join Date
    Aug 2004
    Location
    Brighton
    Posts
    1,563
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    You can try this... I've just been fiddling around with it.

    But I warn you, if I were a web user on your page, this'd annoy me a lot.

    Code:
    <head>
    <SCRIPT LANGUAGE="JavaScript">
    function getit() {
    askit = confirm("Leaving so soon? Why not stay a little longer!");
    if (askit == true)
    window.location=window.location.href
    else
    if (askit == false)
    alert("Visit again soon!");
    }
    </script>
    </head>
    <BODY onunLoad="getit()">
    Your webpage here.
    </body>
    </html>
    cr3ative
    Last edited by cr3ative; 11-17-2004 at 06:51 PM.
    A retired member, drop me a line through my site if you'd like to find me!
    cr3ative media | read the stickies

  8. #8
    Join Date
    Oct 2004
    Posts
    79
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    thanks for the effort, but that is not it...hum. how can I explain this...
    try this:

    <HTML>
    <HEAD>
    <SCRIPT>
    function closeIt()
    {
    event.returnValue = "Any string value here forces a dialog box to \
    appear before closing the window.";
    }
    </SCRIPT>
    </HEAD>
    <BODY onbeforeunload="closeIt()">
    <a href="">Click here to navigate to</a>
    </BODY>
    </HTML>

    try this script...
    now I want the same without the additional text that appears no matter what you write instead of "Any string value here forces a dialog box to \
    appear before closing the window."
    get my point?
    greetz

  9. #9
    Join Date
    Aug 2004
    Location
    Brighton
    Posts
    1,563
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Erm... no, I don't get your point...

    cr3ative
    A retired member, drop me a line through my site if you'd like to find me!
    cr3ative media | read the stickies

  10. #10
    Join Date
    Oct 2004
    Posts
    79
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    the script you modified does not work. when I press cancel, leaves the page, altough it shows an alert.
    I want an alert when I made alt+f4 or righttop X or try to leave the page somehow... and when I say ok in that alert I leave. when I say cancel, I stay.

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
  •