您的位置:首页 > Web前端 > JavaScript

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

2017-05-22 10:50 2586 查看
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>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: