JS 判斷域名並跳轉到指定頁面

判斷訪問指定域名,進行頁面跳轉

<!DOCTYPE html>
<html>
<head>
	<title>正在玩命加載中……</title>
	<!-- 判斷來路域名自動跳轉 -->
	<script type="text/javascript">
	    var href = location.href ;  //獲取當前請求路徑
        if (href.indexOf("vipsoft") > -1) {
            //跳轉
            location.href = "http://www.vipsoft.com.cn/vipsoft.html";
        } else if (href.indexOf("eicrosoft") > -1) {
        	window.location.href='http://www.vipsoft.com.cn/eicrosoft.html';
        }
    </script>
</head>
<body>
 
</body>
</html>

不同的域名 輸出不同的結果

<script type="text/javascript">
        if (window.location.href.indexOf("vipsoft.com.cn") > -1) {
        document.write("<li style='background:none;'><a href='http://www.vipsoft.com.cn/1.html'>介紹</a></li>");
        } else if (window.location.href.indexOf("www.vipsoft.com.cn") > -1) {
        document.write("<li style='background:none;'><a href='http://www.vipsoft.com.cn/2.html'>介紹</a></li>");
        } else if (window.location.href.indexOf("www.eicrosoft.com") > -1) {
        document.write("<li style='background:none;'><a href='http://www.vipsoft.com.cn/3.html'>介紹</a></li>");
        }
 </script>
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章