Javascript重定向无限循环

时间:2017-01-19 21:16:50

标签: javascript html

Chrome未重定向到Intranet站点。 body onload方法无限循环。如果我将目标更改为google.com等外部网站,则重定向会起作用。有人可以指点一下,为什么我的内部网站点存在无限循环?

以下是我的HTML

<!DOCTYPE HTML>
<script type="text/javascript" src="openBrowser.js"></script>
<script type="text/javascript">
function openURL(){
    var targetURL="http://myintranetsite";
    openBrowser(targetURL);
}
</script>

<BODY onLoad="openURL()">
    <div id="loadBrowser"><h1>Opening Browser..</h1></div>
</BODY>
</HTML>

我的javascript

var isChrome = navigator.userAgent.toLowerCase().indexOf('chrome') > -1;
if(isChrome)
    {
        //Changes the URL to destination if the current chrome browser version is 40
        if(getChromeVersion()>=40)
        {               
            window.location=targetURL;                                              
        }
}

2 个答案:

答案 0 :(得分:0)

检查window.location不是您的内部网页

if (window.location.hostname.indexOf("myintranetsite") > -1) {
    openBrowser(targetURL);
}

或者稍后可能会刹车:

if (window.location.toString() != targetURL && getChromeVersion()>=40) {               
    window.location=targetURL;                                              
}

答案 1 :(得分:0)

您的代码必须重定向到版本40或更高的版本,您必须看到您还没有到达您想去的地方,导致无限重定向。这是可以为您工作的代码

  var isChrome = navigator.userAgent.toLowerCase().indexOf('chrome') > -1;
  if(isChrome)
  {
          //Changes the URL to destination if the current chrome browser version is 40
          if(getChromeVersion()>=40 && window.location!==targetURL)
          {               
              window.location=targetURL;                                              
          }
  }