1.如何利用JS判斷當前來路域名並跳轉到指定頁面
獲取當前請求路徑
var href = location.href ;
if(href.indexOf("baidu")>-1){
//跳轉
location.href = "http://baidu.com";
}
2.
今天有一客戶要求他的網站輸入兩個不同的域名后需要載入不同網頁頭部。思前想來,也只有通過JS的判斷來加載不同的CSS。
代碼如下:
host = window.location.host;
if (host=="www.028wz.net")
{
document.write("<style>")
document.write(".head{ background: url(document.write("</style>")
}
3.不同的域名 輸出不同的結果
<script type="text/javascript"> if (window.location.href.indexOf("www.xt.com") > -1) { document.write("<li style='background:none;'><a href='http://www.xt.com/yygk/yyjj/915.html'>介紹</a></li>"); } else if (window.location.href.indexOf("www.gzxt.com") > -1) { document.write("<li style='background:none;'><a href='http://www.gzxt.com/yygk/yyjj/916.html'>介紹</a></li>"); } else if (window.location.href.indexOf("www.gzxt.com") > -1) { document.write("<li style='background:none;'><a href='http://www.gzxt.com/yygk/yyjj/917.html'>介紹</a></li>"); } </script>