Javascript; Sending user to another page

Anomynous picture Anomynous · Nov 16, 2008 · Viewed 61.2k times · Source

I am trying to send a user to another page using a Javascript Function:

<input type="button" name="confirm" value="nextpage" onClick="message()">

And my JavaScript:

function message() {
    ConfirmStatus = confirm("Install a Virus?");

    if (ConfirmStatus == true) {
        //Send user to another page
    }
}

Does anyone know how to send a user to another specific page?

Answer

Jos&#233; Leal picture José Leal · Nov 16, 2008

your code got messed up, but if I got it right you can use the following:

location.href = 'http://www.google.com';
or
location.href = 'myrelativepage.php';

Good luck!

But I must say to you,

  1. Javascript can be turned off, so your function won't work.

Other option is to do this by code:

PHP: header('Location: index.php');

C#: Response.Redirect("yourpage.aspx");

Java: response.sendRedirect("http://www.google.com");

Note:

  1. All of those redirects must be placed before any outputs to the client ok?