redirects w/ js

Discussion in 'Javascript' started by Magic-chef, Jun 29, 2003.

  1. Magic-chef

    Magic-chef Guest

    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?
    Magic-chef, Jun 29, 2003
    1. Advertisements

  2. 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.
    David Dorward, Jun 29, 2003
    1. Advertisements

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 (here). After that, you can post your question and our members will help you out.