How to redirect from one URL to another URL?

前端 未结 7 576
忘了有多久
忘了有多久 2020-12-05 02:22

How can I redirect to another URL in a web page using JavaScript?

相关标签:
7条回答
  • 2020-12-05 02:55

    You can redirect anything or more URL via javascript, Just simple window.location.href with if else

    Use this code,

    <script>
    if(window.location.href == 'old_url')
    {
        window.location.href="new_url";
    }
    
    
    //Another url redirect
    if(window.location.href == 'old_url2')
    {
        window.location.href="new_url2";
    }
    </script>
    

    You can redirect many URL's by this procedure. Thanks.

    0 讨论(0)
  • 2020-12-05 02:56
    location.href = "Pagename.html";
    
    0 讨论(0)
  • 2020-12-05 03:14
    window.location.href = "URL2"
    

    inside a JS block on the page or in an included file; that's assuming you really want to do it on the client. Usually, the server sends the redirect via a 300-series response.

    0 讨论(0)
  • 2020-12-05 03:15

    If you want to redirect, just use window.location. Like so:

    window.location = "http://www.redirectedsite.com"
    
    0 讨论(0)
  • 2020-12-05 03:15

    Why javascript?

    http://www.instant-web-site-tools.com/html-redirect.html

    <html>
    <meta http-equiv="REFRESH" content="0;url=http://www.URL2.com"> 
    </html>
    

    Unless I'm missunderstanding...

    0 讨论(0)
  • 2020-12-05 03:19

    you can also use a meta tag to redirect to another url.

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

    http://webdesign.about.com/od/metataglibraries/a/aa080300a.htm

    0 讨论(0)
提交回复
热议问题