Javascript; Sending user to another page

前端 未结 6 2107
情深已故
情深已故 2021-02-19 01:07

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


<         


        
相关标签:
6条回答
  • 2021-02-19 01:54

    try this: window.location.href = "YOUR_RELATIVE_PATH_HERE" ex ./pages/aboutus"

    0 讨论(0)
  • 2021-02-19 01:55

    You can also use a meta refresh tag to redirect.

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

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

    0 讨论(0)
  • 2021-02-19 02:03

    try this!

    window.location.replace("http://www.link.com");
    
    0 讨论(0)
  • 2021-02-19 02:03

    window.location.href = url;

    It is ok for redirecting to the required url using javascript.

    The simple example can be found in this url

    0 讨论(0)
  • 2021-02-19 02:07

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

    0 讨论(0)
  • 2021-02-19 02:08

    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?
    0 讨论(0)
提交回复
热议问题