如何利用JS判断当前来路域名并跳转到指定页面
用户投稿 学习笔记 12阅读
1.如何利用JS判断当前来路域名并跳转到指定页面
var href = location.href ; //获取当前请求路径if(href.indexOf("baidu")>-1){ //跳转 location.href = "http://baidu.com";}2.输入不同的域名后载入不同网页头部,可以通过JS的判断来加载不同的CSS。
代码如下:
var host = window.location.host;if (host=="lezi.66ghz.com") { document.write("<style>") document.write(".head{ background: url(XXX)}") document.write("</style>")}3.不同的域名 输出不同的结果
<script type="text/javascript"> if (window.location.href.indexOf("seekstack.cn") > -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("s.seekstack.cn") > -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来操作比较简单粗暴一点,吧上面这段一改就成自己的了,把下面这个文件往根目录一丢,万事大吉,哈哈哈。。。
<!DOCTYPE html><html><head><title>正在玩命加载中……</title><!-- 判断来路域名自动跳转 --><script type="text/javascript"> if (window.location.href.indexOf("lezi.66ghz.com") > -1) { window.location.href='http://seekstack.cn'; } else if (window.location.href.indexOf("tttp://s.thevv.top") > -1) { window.location.href='tttp://s.seekstack.cn'; } else if (window.location.href.indexOf("www.bookhai.top") > -1) { window.location.href='http:/seekstack.cn/book/'; } </script></head><body></body></html>
标签: