Forum Moderators: open

Message Too Old, No Replies

Javascript Redirection

Bit of a newbie question

         

sjthomas

11:59 pm on Sep 11, 2004 (gmt 0)

10+ Year Member



Hi there, I was wondering how you would redirect a user using a javascript as opposed to using the meta refresh tag. Basically I want to re-direct a user to the address stored in a PHP variable called destination after 5 seconds.

I've tried a few ways I came up with but with no success. I'm the first to admit that I suck at javascript lol.

Many thanks

fish_eye

12:38 am on Sep 12, 2004 (gmt 0)

10+ Year Member



If you are on an Apache server then you can do a redirect (and a whole lot more) with mod_rewrite - but it sounds like you may want the URL to be context sensitive?

Considering that you're using PHP - you could always build the html meta tag that does a redirect <meta http-equiv="refresh" etc) (but then you said you wanted to avoid the meta tag...)

Why does it have to be JS?

sjthomas

1:12 am on Sep 12, 2004 (gmt 0)

10+ Year Member



The reason I'm trying to avoid using the meta refresh tag is because, apparently, it messes with the way SE's index your site. I've heard that having a meta refresh on your site means that the SE assumes that your tricking the user into visiting a page other than the one they want to! Talk about tarring everyone with the same brush! Even though I'm using the re-direct for a legit purpose I'd rather not take the risk.

Cheers.

saul11

3:51 pm on Sep 12, 2004 (gmt 0)

10+ Year Member



The code will be something like this

setTimeout("document.location = <?=$destination?>", 5000);

- setTimeout evaluates an expression or calls a function once after a specified number of
milliseconds elapses.

- If you assign a string to the location property of an object, JavaScript creates a
location object and assigns that string to its href property. For example, the
following two statements are equivalent and set the URL of the current window
to the Netscape home page:
window.location.href="http://home.netscape.com/"
window.location="http://home.netscape.com/"

(I'm not really sure if the PHP code is placed correctly, so you may have to tweak this)