Forum Moderators: open
<html>
<head>
<title>JS Redirect</title>
</head>
<body>
<a id="home" href="index.html">Home</a>
<a id="contact" href="contact.html">Contact</a>
<a id="support" href="support.html">Support</a>
</body>
</html>
Would there be any javascript I could put in the <head> of the page to select a link with a particular id and automatically redirect to it after the page has been loaded for five seconds or so?
Meta redirects and standard js redirects won't work; I've got to be able to select a link from one that's already in the <body> of the page.
I know this concept sounds wacky, but I really do have a good, "user-convenience" reason for doing this! ;)
Thanks,
Matthew
So, yes, DrDoc's, or this below, if you would prefer the redirecting page not to reappear when the user goes back through history
location.replace(document.getElementById('foobar').href); Come to think of it, referencing the link like this will save all of 1/2 a microsecond, and afford you a little backward-compatibility:
document.links['foobar']
<html><head>
<title>Redirect</title>
<script type="text/javascript">location.replace(document.getElementById('foobar').href);</script>
</head>
<body>
<a id="foobar" href="blah.html">Blah</a>
</body>
</html>
Tried this with each of the lines you guys provided, but none of them redirected. Apparently I'm missing how to implement this. Could you please explain the context of how I'd go about using the script?
And then perhaps point me to a good, from-the-ground-up tutorial on JavaScript? ;)
Thanks again,
Matthew
I see people recommend W3 Schools a lot
JavaScript: [w3schools.com ]
DHTML: [w3schools.com ]
For pure JavaScript:
[devedge.netscape.com ]
This cuts the corners to tell you things it might take a while to find out:
[crockford.com ]
This article will put you on the straight-and-narrow on an important topic:
[jibbering.com ]
Then return to WebmasterWorld JavaScript!
Also of great utility is "Dynamic HTML: The Definitive Guide", also on O'Reilly. It's coverage of the DOM is the best I've seen, by a significant margin.