-1){ //跳转 location.href = "http:/">
当前位置:Gxlcms > JavaScript > 如何用JS判断当前域名并跳转到指定页面

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

时间:2021-07-01 10:21:17 帮助过:7人阅读

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>

以上就是如何用JS判断当前域名并跳转到指定页面的详细内容,更多请关注Gxl网其它相关文章!

人气教程排行