how to redirect to home page

前端 未结 8 1296
时光说笑
时光说笑 2021-02-01 11:45

How can I redirect a user to home page?

Example: mywebsite.com/ddfdf/fdfdsf and I want to redirect to mywebsite.com

However I want to do it wit

相关标签:
8条回答
  • 2021-02-01 12:14

    Can you do this on the server, using Apache's mod_rewrite for example? If not, you can use the window.location.replace method to erase the current URL from the back/forward history (to not break the back button) and go to the root of the web site:

    window.location.replace('/');
    
    0 讨论(0)
  • 2021-02-01 12:21
    document.location.href="/";
    
    0 讨论(0)
  • 2021-02-01 12:21
    window.location = '/';
    

    Should usually do the trick, but it depends on your sites directories. This will work for your example

    0 讨论(0)
  • 2021-02-01 12:24
    document.location.href="/";
    

    or

     window.location.href = "/";
    

    According to the W3C, they are the same. In reality, for cross browser safety, you should use window.location rather than document.location.

    See: http://www.w3.org/TR/Window/#window-location

    (Note: I copied the difference explanation above, from this question.)

    0 讨论(0)
  • 2021-02-01 12:30

    strRetMsg ="<script>window.location.href = '../Other/Home.htm';</script>";

    Page.ClientScript.RegisterStartupScript(this.GetType(), "Script", strRetMsg,false);

    Put this code in Page Load.

    0 讨论(0)
  • 2021-02-01 12:31
    window.location.href = "/";
    

    This worked for me. If you have multiple folders/directories, you can use this:

    window.location.href = "/folder_name/";
    
    0 讨论(0)
提交回复
热议问题