Results 1 to 5 of 5

Thread: Whats the javascript command for exit ?

  1. #1
    HEXUS.social member Agent's Avatar
    Join Date
    Jul 2003
    Location
    Internet
    Posts
    19,168
    Thanks
    735
    Thanked
    1,607 times in 1,045 posts

    Question Whats the javascript command for exit ?

    ive got
    Code:
    <SCRIPT language="JavaScript">
    <!--
    function go_there()
    {
     var where_to= confirm("Do you really want to go to this page??");
     if (where_to== true)
     {
       window.location="http://yourplace.com/yourpage.htm";
     }
     else
     {
      window.location="http://www.blahhhh.com";
      }
    }
    //-->
    </SCRIPT>
    I want to change it so if the user doesnt click OK, the script dies and doesnt do anything else.
    Ive tried taking the else section out, but it still redirects to the first URL even when you click cancel.

    Any offers ?

    Thanks.
    Quote Originally Posted by Saracen View Post
    And by trying to force me to like small pants, they've alienated me.

  2. #2
    Senior Member Shad's Avatar
    Join Date
    Jul 2003
    Location
    In front
    Posts
    2,773
    Thanks
    22
    Thanked
    40 times in 24 posts
    Check the output for the confirm dialog. I'd do it slightly differently though (because I don;t really know the answer to your problem!):

    Code:
    <a href="http://www.google.com" onclick="return confirm('Visit Google?')">
    Not very practicle if you have 100 links to use the script on.
    Simon


  3. #3
    bored out of my tiny mind malfunction's Avatar
    Join Date
    Jul 2003
    Location
    Lurking
    Posts
    3,923
    Thanks
    191
    Thanked
    187 times in 163 posts
    • malfunction's system
      • Motherboard:
      • Gigabyte G1.Sniper (with daft heatsinks and annoying Killer NIC)
      • CPU:
      • Xeon X5670 (6 core LGA 1366) @ 4.4GHz
      • Memory:
      • 48GB DDR3 1600 (6 * 8GB)
      • Storage:
      • 1TB 840 Evo + 1TB 850 Evo
      • Graphics card(s):
      • 290X
      • PSU:
      • Antec True Power New 750W
      • Case:
      • Cooltek W2
      • Operating System:
      • Windows 10
      • Monitor(s):
      • Dell U2715H
    Erm... It works fine for me when I take out the else part...

    Just a note on style though - you don't need to stick the result of confirm() in a varible or use "== true"...

    Code:
    <script>
        if (confirm("If you click OK I'll be annoying and say \"You clicked OK!\"")) {
            alert("You clicked OK!")
        }
    </script>
    Though that's really personal style

  4. #4
    HEXUS.social member Agent's Avatar
    Join Date
    Jul 2003
    Location
    Internet
    Posts
    19,168
    Thanks
    735
    Thanked
    1,607 times in 1,045 posts
    Same as PHP then malfunction
    Im a PHP guy - know nothing of java.
    What Shad has shown should be fine for the moment

    Thanks both if you
    Quote Originally Posted by Saracen View Post
    And by trying to force me to like small pants, they've alienated me.

  5. #5
    bored out of my tiny mind malfunction's Avatar
    Join Date
    Jul 2003
    Location
    Lurking
    Posts
    3,923
    Thanks
    191
    Thanked
    187 times in 163 posts
    • malfunction's system
      • Motherboard:
      • Gigabyte G1.Sniper (with daft heatsinks and annoying Killer NIC)
      • CPU:
      • Xeon X5670 (6 core LGA 1366) @ 4.4GHz
      • Memory:
      • 48GB DDR3 1600 (6 * 8GB)
      • Storage:
      • 1TB 840 Evo + 1TB 850 Evo
      • Graphics card(s):
      • 290X
      • PSU:
      • Antec True Power New 750W
      • Case:
      • Cooltek W2
      • Operating System:
      • Windows 10
      • Monitor(s):
      • Dell U2715H
    Yeah Javascript (and actual Java) have a very C like syntax - same as PHP... Much nicer than nasty vbscript IMO

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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