Home > Web Front-end > JS Tutorial > body text

Use js to determine the origin of the current URL and jump to the specified page if it is not the specified origin_javascript skills

WBOY
Release: 2016-05-16 18:07:04
Original
1461 people have browsed it
Copy code The code is as follows:




Recommended

Copy code The code is as follows:

<script><br>function isMatch(str1, str2) <br>{ <br>var index = str1.indexOf(str2); <br>if(index==-1) return false; <br>return true; <br>} <br>alert(window. location.hostname);<br>if (isMatch(window.location.hostname,'www.jb51.net') == false){window.location.href="http://www.jb51.net";} <br></script>

The following is used in one of our website development

Copy code The code is as follows:

function gotourl()
{
var url = "http://www.jb51.net";
var localurl = document.url;
if( localurl.substring(0,url.length) != url )
{
location.href=url;
}
}
gotourl();
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