zoukankan      html  css  js  c++  java
  • 如何利用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>
  • 相关阅读:
    小程序模板
    小程序 if else
    小程序入门小知识
    懒加载
    展示效果
    五星评价
    萤火虫效果
    下雪效果
    选项卡
    VUE组件中 data 里面的数据为什么要return 出来
  • 原文地址:https://www.cnblogs.com/lazb/p/6888422.html
Copyright © 2011-2022 走看看