简体   繁体   English

此代码在使用 Internet Explorer 打开时工作正常,但在我使用 firefox 或其他浏览器打开时无法工作

[英]This code works fine when opened with internet explorer but fails to work when i open it with firefox or other browsers

This code works fine when running in IE.此代码在 IE 中运行时运行良好。 I get a request asking to allow blocked content due to the use of activeX.由于使用了 activeX,我收到一个请求,要求允许被阻止的内容。 But when I run it in firefox and other browsers.. I get nothing.但是当我在 firefox 和其他浏览器中运行它时......我什么也没得到。 Kindly help.请帮忙。

    var httpRequest;
    try  
    {
      httpRequest = new XMLHttpRequest();  // Mozilla, Safari, etc
    }
    catch(trymicrosoft)
    {
      try
      {
        httpRequest = new ActiveXObject("Msxml2.XMLHTTP");
      }
      catch(oldermicrosoft)
      {
        try
        {
          httpRequest = new ActiveXObject("Microsoft.XMLHTTP");
        }
        catch(failed)
        {
          httpRequest = false;
        }
      }
    }
    if(!httpRequest)
    {
      alert('Your browser does not support Ajax.');
      return false;
    }

    //===============================
    // Action http_request
    var finaltxt;
    //do{
    httpRequest.onreadystatechange = function()
    {
      if(httpRequest.readyState == 4)
      if(httpRequest.status == 200)
        {
              var txt = httpRequest.responseText;
              var index = txt.search(/regular/i);
      var index1 = txt.search(/to see hours/i);
      finaltxt = txt.substring(index,index1);
              document.write("<IMG " +"SRC='web2.jpg'>");
              document.write("<br>"+ finaltxt.fontsize(2) + "<br>");
              return finaltxt;
          }

        else
              return finaltxt;
    }
    httpRequest.open('GET','http://xyz',true);
    httpRequest.send(null);
    return finaltxt;

It is to be expected.这是可以预料的。 As you are using ActiveX (just for IE - Not Firefox etc).当您使用 ActiveX(仅适用于 IE - 不是 Firefox 等)。 It is a security measure for IE.这是 IE 的一种安全措施。

switch to use a javascript library like jquery that supports multi=browser support.. you will never have to write code like this again..切换到使用 javascript 库,例如支持多浏览器支持的 jquery ..您将永远不必再编写这样的代码..

see the ajax api in particular.尤其参见ajax api

Check out jquery查看jquery

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 .js代码中给出的document.location()函数在Internet Explorer中可以正常工作,但在Firefox中不起作用 - document.location() function given in the .js code works fine in Internet Explorer but does not work in Firefox 无序列表中的列表项仅在Internet Explorer中重叠,在所有其他浏览器中一切正常 - List items in an unordered list are overlapping only in Internet Explorer, everything works fine in all other browsers 可以在firefox中使用但在所有其他浏览器中均无法使用的jquery.ajax代码 - jquery.ajax code that works in firefox but fails in all other browsers 我的Javascript代码在IE中不起作用,但在其他浏览器中也可以正常工作 - My Javascript code does not work in IE but works fine in other browsers 该网站可以在除Firefox之外的其他浏览器上正常运行 - Site works fine on other browsers except for Firefox 仅当我在Chrome上缓存刷新时,网站才能完全正常运行,在其他浏览器上也可以正常运行 - Website only works completely when I cache refresh on Chrome, works fine on other browsers HTML问题仅在Internet Explorer上。 在其他浏览器上都可以正常工作 - HTML Issue on Internet Explorer only. It works fine on the rest of the browsers 我的Optin表单在Internet Explorer中不起作用,但在Firefox中可以正常工作 - My Optin form doesn't work in Internet Explorer, but works fine in Firefox JavaScript Button.click() 在 Firefox 中不起作用,在 Internet Explorer 中工作正常 - JavaScript Button.click() does not work in Firefox, works fine in Internet Explorer 我的代码在Firefox中有效,但在Internet Explorer中不起作用 - My code works in Firefox but not Internet Explorer
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM