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

Load different web page from a hyperlink

manuelgk
P: 54
Hi!, does anybody know how to load a different Web page using a hyperlink?. Now I have my code with some "<a href>" when I click the link, it load the URL of the <a href>. My question is how can I force the navigator with JS to load a different Web page?. For example, if I click the link of google( [HTML]<a href='http://www.google.com.mx'>Google</a>[/HTML] ) the result of the event it will not the google Web page!!!, so the navigator displays a Web page define in my script (for example www.yahoo.com). I know it could be a stupid question, because easily I can change the reference in the <a> tags, but as I said in another discussion, I'm a total beginner and I try new things with JS.

Thank you again!!!
Oct 8 '07 #1
Share this Question
Share on Google+
3 Replies


gits
Expert Mod 5K+
P: 5,390
hi ...

here's an example, that switches the href of the link when the page is loaded:

Expand|Select|Wrap|Line Numbers
  1. <script type="text/javascript">
  2. function switch_href() {
  3.     var l = document.getElementById('my_link');
  4.     l.href = 'your_new_url';
  5. }
  6. </script>
  7.  
  8. <body onload="switch_href();">
  9.     <a id="my_link" href="http://www.google.com.mx">Google</a>
  10. </body>
  11.  
kind regards
Oct 8 '07 #2

manuelgk
P: 54
Ok got it!, thanks for replied, It's really useful
Oct 8 '07 #3

gits
Expert Mod 5K+
P: 5,390
post back to the forum anytime you have more questions :)

kind regards
Oct 9 '07 #4

Post your reply

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