By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,720 Members | 2,237 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,720 IT Pros & Developers. It's quick & easy.

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

Blue1244
P: 39
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.
Expand|Select|Wrap|Line Numbers
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <title>
  5. Math Game
  6. </title>
  7. <style>
  8. </style>
  9. </head>
  10. <body>
  11. <script type="text/JavaScript">
  12. function start()
  13. {
  14. var a= confirm("Are you sure you want to continue to the game?");
  15. if (a==true)
  16. {
  17. //Here is where it should take the viewer to the other html document.
  18. }
  19. else
  20. {
  21. window.close();
  22. }
  23. }
  24. </script>
  25. <center><button onClick="start()">Start</button></center>
  26. </body>
  27. </html>
  28.  
Aug 22 '13 #1

✓ answered by shadowstrike

Hi
I went through yout code and I thought the easiest way to acheiv what you want is by this method:-
Expand|Select|Wrap|Line Numbers
  1. <button onClick="window.location.href='html_page_where_you_want_to_navigate.html'" />
  2.  
Lemme know id that works

Share this Question
Share on Google+
7 Replies


Dormilich
Expert Mod 5K+
P: 8,639
If you need my code ask and I will post.
yepp, we will need to see your code.
Aug 23 '13 #2

Blue1244
P: 39
Ok I will edit the post.
I still have some work to do on it before I can post it.
Aug 23 '13 #3

Blue1244
P: 39
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.
Aug 23 '13 #4

Dormilich
Expert Mod 5K+
P: 8,639
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.
Aug 24 '13 #5

P: 21
Hi
I went through yout code and I thought the easiest way to acheiv what you want is by this method:-
Expand|Select|Wrap|Line Numbers
  1. <button onClick="window.location.href='html_page_where_you_want_to_navigate.html'" />
  2.  
Lemme know id that works
Aug 24 '13 #6

Blue1244
P: 39
Yes it worked! Thank you. I added the
Expand|Select|Wrap|Line Numbers
  1. start();
before the
Expand|Select|Wrap|Line Numbers
  1. window.location.href='nextpage.html'
and it worked :D.
Expand|Select|Wrap|Line Numbers
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <title>
  5. Home Page
  6. </title>
  7. <style>
  8. </style>
  9. </head>
  10. <body>
  11. <script type="text/JavaScript">
  12. function start()
  13. {
  14. var a= confirm("Are you sure you want to continue to the game?");
  15. if (a==true)
  16. {
  17. //Here is where it should take the viewer to the other html document.
  18. }
  19. else
  20. {
  21. window.close();
  22. }
  23. }
  24. </script>
  25. <center><button onClick="start(); window.location.href='page_1.html'" />
  26.  Start</button></center>
  27. </body>
  28. </html>
  29.  
  30.  
Aug 24 '13 #7

P: 21
your welcome..... :D......
Aug 24 '13 #8

Post your reply

Sign in to post your reply or Sign up for a free account.