脚本和表单适用于Firefox,但不适用于Chrome / IE。帮忙调试?

时间:2015-04-23 18:40:22

标签: javascript forms google-chrome

直播:http://umiss.lib.olemiss.edu/screens/urlconverter.html 该表单适用于Firefox,但不适用于Chrome或IE。在Firefox中,您输入一个URL并显示新的代理URL。它还将旧的代理URL转换为新格式。在Chrome和IE中,转换按钮不会显示任何内容。有什么建议吗?

    <script type="text/javascript">


function displayProxyUrl() {
     url = document.getElementById('url').value;
     document.getElementById('proxyurl').value = checkUrl(url);
}

 function checkUrl (url){
  if (url.contains ("http://0")>-1){
    return "http://umiss.idm.oclc.org/login?url=" + url.replace("0-","").replace(".umiss.lib.olemiss.edu","");
     }
  else
    return "http://umiss.idm.oclc.org/login?url=" + url;
}  


   </script>

</p>
<form action="javascript:void(0)" onsubmit="gotoProxyUrl(); return false;">
  <p align="center"><strong>URL Converter      </strong></p>
  <p align="center">This form will convert both current proxied URLs (starting 0-) and base URLS (http://www.jstor.org). </p>
  <p>URL:&nbsp;
  <input type="url" name="url" id="url" size="100" /> 
      <p>
        <input type="button" value="Convert to Proxy URL " style="width: 10em;" onclick="displayProxyUrl()" />
      <p>New Proxy URL:&nbsp; 
        <input type="text" name="proxyurl" id="proxyurl" size="100" onfocus="this.select()" readonly="readonly" />
    <p>    
  <p>NOTE: If the URL ends in .pl (http://www.olemiss.edu/cgi-bin/library/aph.pl), don't convert it; they remain the same.
</form>

1 个答案:

答案 0 :(得分:1)

而不是contains使用indexOf

if(url.indexOf("http://0") != -1) {
    //do your things
}

Further read on indexOf()

修改

.contains()(和.includes())是实验函数(ECMAScript 6提案的一部分)。他们没有跨浏览器支持。 (例如,不在Chrome中工作)

Check this for further information