📌  相关文章
📜  如何重定向到 HTML 中的另一个网页?

📅  最后修改于: 2021-11-08 05:55:32             🧑  作者: Mango

通常需要在加载网页时重定向到另一个网页,例如,由于内容被移动到新网页。

这里演示了两种在加载时重定向到另一个网页的简单方法。

方法 1:在 HTML 中使用元标记的http-equiv 属性。

句法:


示例 1:



  

    
        Redirect to GeeksforGeeks
    
    
    

  

    
    You will be redirected to GeeksforGeeks in a moment.
    
      If you are not redirected automatically,             click here     .   

输出:
前:

2 秒后:

注意:在某些较旧的浏览器中,例如 Internet Explorer 6,刷新可能会导致意外结果并损害浏览器的后退按钮。这在大多数现代浏览器(Internet Explorer 7 及更高版本、Google Chrome、Mozilla Firefox、Microsoft Edge)中得到了补偿。

方法 2:在 JavaScript 中使用location.href。

句法:

window.location.href = "URL"

示例 2:



  

    
        Redirect to GeeksforGeeks
    
    

  

    
    You will be redirected to GeeksforGeeks in a moment.
    
    If you are not redirected automatically,         click here     .   

输出:

注意:此方法适用于任何支持 JavaScript 的浏览器。