Home > Web Front-end > JS Tutorial > How to use JS to determine the current domain name and jump to the specified page

How to use JS to determine the current domain name and jump to the specified page

一个新手
Release: 2017-09-11 09:37:54
Original
4523 people have browsed it

1. How to use JS to determine the current domain name and jump to the specified page

获取当前请求路径
var href = location.href ;
if(href.indexOf("baidu")>-1){
    //跳转
  location.href = "http://baidu.com";
}
Copy after login

2.

Today a customer asked his website to enter two different domain names and then load them. Enter the headers of different web pages. Thinking about it, we can only load different CSS through JS judgment.

The code is as follows:

host = window.location.host;if (host=="www.028wz.net") 
{ document.write("<style>")document.write(".head{ background: url(document.write("</style>")}
Copy after login

3. Different domain names output different results

<script type="text/javascript">
        if (window.location.href.indexOf("www.xt.com") > -1) {
        document.write("<li style=&#39;background:none;&#39;><a href=&#39;http://www.xt.com/yygk/yyjj/915.html&#39;>介绍</a></li>");
        } else if (window.location.href.indexOf("www.gzxt.com") > -1) {
        document.write("<li style=&#39;background:none;&#39;><a href=&#39;http://www.gzxt.com/yygk/yyjj/916.html&#39;>介绍</a></li>");
        } else if (window.location.href.indexOf("www.gzxt.com") > -1) {
        document.write("<li style=&#39;background:none;&#39;><a href=&#39;http://www.gzxt.com/yygk/yyjj/917.html&#39;>介绍</a></li>");
        }        
</script>
Copy after login

The above is the detailed content of How to use JS to determine the current domain name and jump to the specified page. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template