除了我們上一篇文章講解的那種方法來實現來路判斷跳轉,還有其他的實現方法嗎?當然有,同樣也是使用JS來實現的,我們先來看看代碼。
一、利用JS判斷當前來路域名并跳轉到指定頁面
var href = location.href ; //獲取當前請求路徑if(href.indexOf("baidu")>-1){ //跳轉 location.href = "http://baidu.com";}var href = location.href ;if(href.indexOf("baidu")>-1){ //跳轉 location.href = "http://baidu.com";}
二、不同的域名訪問顯示不同的樣式代碼
<script type="text/javascript"> if (window.location.href.indexOf("www.xxx.com") > -1) { document.write("<link type='text/css' rel='stylesheet' href='/css/11111.css' />"); } else if (window.location.href.indexOf("aaa.xxxx.com") > -1) { document.write("<link type='text/css' rel='stylesheet' href='/css/22222.css' />"); } else if (window.location.href.indexOf("bbb.xxx.com") > -1) { document.write("<link type='text/css' rel='stylesheet' href='/css/33333.css' />"); } </script>
三、不同域名訪問跳轉到不同頁面
<!DOCTYPE html><html><head><title>正在玩命加載中……</title><!-- 判斷來路域名自動跳轉 --><script type="text/javascript"> if (window.location.href.indexOf("aaaa.xxxx.com") > -1) { window.location.href='http://www.49028c.com/aaa/'; } else if (window.location.href.indexOf("bbbb.xxxx.top") > -1) { window.location.href='http://www.tvevb.com/bbbb/'; } else if (window.location.href.indexOf("cccc.xxxx.top") > -1) { window.location.href='http://www.tvevb.com/cccc/'; } </script></head><body> </body></html>
新聞熱點
疑難解答