jQuery 重定向

如何使用 jQuery 将页面重定向到 URL。

搜索引擎使用 301 状态代码将页面排名从旧 URL 转移到新 URL。

jQuery 重定向返回 http 响应状态代码:200 OK。

因此,jQuery 重定向与 Javascript 重定向一样,对搜索引擎不友好,最好使用其他返回状态代码 301 Moved Permanently 的重定向方法。

jQuery 重定向实际上是Javascript 重定向使用 jQuery 重定向被认为是矫枉过正,因为您可以使用更少的代码进行纯Javascript 重定向

jQuery 重定向

Replace old page with redirection code 为您要重定向到的页面的 URL。

旧页面.html:

<!DOCTYPE html>
<html>
<body>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<脚本类型="text/javascript">
   // jQuery URL 重定向
   $(document).ready( function() {
      url = "http://www.mydomain.com/new-page.html";
      $( location ).attr( "href", 网址);
   });
</脚本>
</正文>
</html>

jQuery 重定向示例

jquery-redirect-test.htm

<!DOCTYPE html>
<html>
<body>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script type="text/javascript">
   $(document).ready( function() {
      url = "https://cmtoinchesconvert.com/zh-CN/web/dev/jquery-redirect.htm";
      $(location).attr("href", url);
   });
</script>
</body>
</html>

 

按此链接可从 jquery-redirect-test.htm 重定向回此页面:

 

jQuery 重定向测试

 

 

JavaScript 重定向 ►

 


也可以看看

Advertising

WEB开发
°• CmtoInchesConvert.com •°