Home  >  Article  >  Web Front-end  >  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

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
WBOYOriginal
2016-05-16 18:07:041436browse
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();
Statement:
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