redirects w/ js

M

Magic-chef

I have a site with PHP code that I need to have a js function to
redirect to another page or site. I am just trying to learn JS and need
a starting palce. Would this be difficult?
 
D

David Dorward

Magic-chef said:
I have a site with PHP code that I need to have a js function to
redirect to another page or site. I am just trying to learn JS and need
a starting palce. Would this be difficult?

Difficult, no, just set a new value for the window.location object.

But its probably the wrong way to do things, redirection using JavaScript is
almost always suboptimal compared to redirection using http (with a header
you can set using PHP) or even HTML (with the ugly meta redirect thing).
About the only time when redirecting using JS is apropriate is as part of a
test for JavaScript (and then only when the code can't be made to
gracefully degrade[1] so alternatives have to be provided).


[1] Rare, very rare. At least when an alternative can be provided.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top