Click to See Complete Forum and Search --> : href?


lmccord2
05-09-2003, 03:32 PM
I download scripts and modify them a little (text) to fit my needs so I'm pretty stupid with javascript... I just want to know how to make a link in javascript. Like <a href=somepage.html>test</a> only it is in the script and it automaticly redirects you. I've been using window.location.replace, but thats cheesy cause you can't hit your back button, it erases the history :(. So please help.

Thanks...

GavinPearce
05-09-2003, 03:50 PM
i think i get wot u mean

You want to forward someone to another page but still let them hit the back button?

It's basically the same. Ummm I'll go write a code. My computer is a bit dodged so if i dont post a code im soz but im to busy to tryin to fix this.

Nearly anyone here can help don't worry.

fakeName
05-09-2003, 04:09 PM
You could use the following. However, you didn't say when you want the redirect to happen.


<html>
<head>
<title></title>
<script language="JavaScript" type="text/javascript">
<!--
function goThere()
{
window.location.href = 'http://www.google.com/'
}
//-->
</script>

</head>
<body onLoad="goThere();">

<p><a href="http://www.google.com">Click here if you are not redirected</a></p>

</body>
</html>

GavinPearce
05-09-2003, 04:10 PM
just got in before me with the code. Yea wot posted above will work just set the timeout. :p

fakeName
05-09-2003, 04:15 PM
Right, you could set the timeout. Not sure if our friend wants this to happen onLoad though. It kind of defeats the purpose if every time they hit the back button they are again redirected.

Okay , they click it fast to breeze back beyone the page with the script, but many people wouldn't know that.

<script language="JavaScript" type="text/javascript">
<!--
function goThere()
{
setTimeout("window.location.href = 'http://www.google.com/'", 5000)
}
//-->
</script>

lmccord2
05-09-2003, 04:22 PM
Thanks!

GavinPearce
05-09-2003, 04:27 PM
thats wot i thought but if he waz usin window location replace it almost an instant thing anyway so i guessed he wanted it 4 that type of thin.