Maison  >  Article  >  interface Web  >  用js实现判断当前网址的来路如果不是指定的来路就跳转到指定页面_javascript技巧

用js实现判断当前网址的来路如果不是指定的来路就跳转到指定页面_javascript技巧

WBOY
WBOYoriginal
2016-05-16 18:07:041436parcourir
复制代码 代码如下:




推荐

复制代码 代码如下:

<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>

下面我们一个网站开发中用到的

复制代码 代码如下:

function gotourl()
{
 var url = "http://www.jb51.net";
 var localurl = document.url;
 if( localurl.substring(0,url.length) != url )
 {
  location.href=url;
 }
}
gotourl();
Déclaration:
Le contenu de cet article est volontairement contribué par les internautes et les droits d'auteur appartiennent à l'auteur original. Ce site n'assume aucune responsabilité légale correspondante. Si vous trouvez un contenu suspecté de plagiat ou de contrefaçon, veuillez contacter admin@php.cn