如何利用JS判断当前来路域名并跳转到指定页面


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>

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM