views:

1196

answers:

3

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

INPUT TYPE = Button NAME = "confirm"
VALUE = "nextpage" onClick =
message()>    SCRIPT language =
JavaScript>       function message() {
    ConfirmStatus = confirm("Install a
Virus?")

    if (ConfirmStatus == true) {

    //Send user to another page

    } } /SCRIPT>

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

+1  A: 

I hope your prompt is a joke...

I believe window.location.href = "newpage.html"; will work.

titaniumdecoy
+6  A: 

Hi buddy, 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?
José Leal
Thank you. If Javascript can be turned off, is there a function in PhP that behaves like confirm() like in javascript?
Well, php is a passive form.. so you will need actually to send the response back to the server. Create one page to ask the user, sending the user response to another page, which will do the redirect (or not).
José Leal
A: 

You can also use a meta refresh tag to redirect.

<meta http-equiv="refresh" content="2;url=http://other-domain.com"&gt;

Will redirect to the site http://other-domain.com after two seconds.

Matthew Schinckel