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-TW/web/dev/jquery-redirect.htm";
      $(location).attr("href", url);
   });
</script>
</body>
</html>

 

按此鏈接可從 jquery-redirect-test.htm 重定向回此頁面:

 

jQuery 重定向測試

 

 

JavaScript 重定向 ►

 


也可以看看

Advertising

WEB開發
°• CmtoInchesConvert.com •°