How do I redirect from one html/js document to another within a function?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Blue1244
    New Member
    • Aug 2013
    • 39

    How do I redirect from one html/js document to another within a function?

    How do I redirect from one html/js document to another within a function? I am trying to reduce the amount of code within one function so I don't get confused. Need help. If you need my code ask and I will post.
    Code:
    <!DOCTYPE html>
    <html>
    <head>
    <title>
    Math Game
    </title>
    <style>
    </style>
    </head>
    <body>
    <script type="text/JavaScript">
    function start()
    {
    var a= confirm("Are you sure you want to continue to the game?");
    if (a==true)
    {
    //Here is where it should take the viewer to the other html document.
    }
    else
    {
    window.close();
    }
    }
    </script>
    <center><button onClick="start()">Start</button></center>
    </body>
    </html>
    Last edited by Blue1244; Aug 23 '13, 09:03 PM. Reason: Added the code.
  • Dormilich
    Recognized Expert Expert
    • Aug 2008
    • 8694

    #2
    If you need my code ask and I will post.
    yepp, we will need to see your code.

    Comment

    • Blue1244
      New Member
      • Aug 2013
      • 39

      #3
      Ok I will edit the post.
      I still have some work to do on it before I can post it.

      Comment

      • Blue1244
        New Member
        • Aug 2013
        • 39

        #4
        oh and, Dormilich, I need to know how to run a function form within another function again, the post got deleted because it was too short.

        Comment

        • Dormilich
          Recognized Expert Expert
          • Aug 2008
          • 8694

          #5
          I need to know how to run a function form within another function
          weird question ... look at lines #14 and #21. there you do exactly that.

          Comment

          • shadowstrike
            New Member
            • Aug 2013
            • 21

            #6
            Hi
            I went through yout code and I thought the easiest way to acheiv what you want is by this method:-
            Code:
            <button onClick="window.location.href='html_page_where_you_want_to_navigate.html'" />
            Lemme know id that works

            Comment

            • Blue1244
              New Member
              • Aug 2013
              • 39

              #7
              Yes it worked! Thank you. I added the
              Code:
              start();
              before the
              Code:
              window.location.href='nextpage.html'
              and it worked :D.
              Code:
              <!DOCTYPE html>
              <html>
              <head>
              <title>
              Home Page
              </title>
              <style>
              </style>
              </head>
              <body>
              <script type="text/JavaScript">
              function start()
              {
              var a= confirm("Are you sure you want to continue to the game?");
              if (a==true)
              {
              //Here is where it should take the viewer to the other html document.
              }
              else
              {
              window.close();
              }
              }
              </script>
              <center><button onClick="start(); window.location.href='page_1.html'" />
               Start</button></center>
              </body>
              </html>

              Comment

              • shadowstrike
                New Member
                • Aug 2013
                • 21

                #8
                your welcome..... :D......

                Comment

                Working...