简体   繁体   English

Javascript在Safari中运行,但不适用于Chrome或Firefox

[英]Javascript working in Safari but not Chrome or Firefox

I am not a programmer at all, so I am sorry in advance, but after searching the web I cannot find an answer. 我根本不是程序员,所以我很抱歉,但在搜索网络后我找不到答案。

I am trying to take the inventory search from this website and put it in a Facebook tab. 我正在尝试从该网站进行库存搜索并将其放入Facebook标签页。 I grabbed the code from the website and edited out the headers and footers, which I did not want, in TextEdit. 我从网站上抓取代码并在TextEdit中删除了我不想要的页眉和页脚。 I am only trying to take the inventory search portion. 我只是试图采取库存搜索部分。

When I tested it out in Safari it seemed to work. 当我在Safari中测试它似乎工作。 The inventory search came up and all of the buttons and filters worked perfectly and when I would go to a different page the headers and footers were still gone and just the inventory search was there - perfect. 库存搜索出现了,所有的按钮和过滤器都运行得很好,当我去另一个页面时,页眉和页脚仍然消失,只有库存搜索在那里 - 完美。

However when tested in Chrome and Firefox the buttons and filters did not work at all, and you cannot go past the first page or apply filters. 但是,在Chrome和Firefox中进行测试后,按钮和过滤器根本无法正常工作,您无法浏览第一页或应用过滤器。

So I decided to go to the site (the first page of the inventory search like the link above) and save the source code to my desktop to see if when I opened this in Chrome or Firefox if it would work, and it didn't, no buttons or filters worked, stuck on first page. 所以我决定去网站(库存搜索的第一页,如上面的链接)并将源代码保存到我的桌面,看看我在Chrome或Firefox中打开它是否可行,但它没有,没有按钮或过滤器工作,卡在第一页。 But it did work in Safari. 但它确实在Safari中有效。

What does this mean? 这是什么意思? Should I give up now? 我现在应该放弃吗? I would include the code but it is the longest I have ever seen. 我会包含代码但它是我见过的最长的代码。 All of the testing of the code I did through TextEdit. 我通过TextEdit完成的所有代码测试。

edit : 编辑
Here are the errors in Chrome: 以下是Chrome中的错误:

Uncaught SyntaxError: Unexpected token < Chevy.html:4608 XMLHttpRequest cannot load http://www.erikschevrolet.com/searchVehicles.ajax . 未捕获的SyntaxError:意外的令牌<Chevy.html:4608 XMLHttpRequest无法加载http://www.erikschevrolet.com/searchVehicles.ajax Origin null is not allowed by Access-Control-Allow-Origin. Access-Control-Allow-Origin不允许使用null。
Uncaught Error: XmlRenderEngine = >Unknown error bundle.js:1 XMLHttpRequest cannot load http://www.erikschevrolet.com/searchVehicles.ajax . 未捕获错误:XmlRenderEngine =>未知错误bundle.js:1 XMLHttpRequest无法加载http://www.erikschevrolet.com/searchVehicles.ajax Origin null is not allowed by Access-Control-Allow-Origin. Access-Control-Allow-Origin不允许使用null。
Uncaught Error: XmlRenderEngine = >Unknown error bundle.js:1 XMLHttpRequest cannot load http://www.erikschevrolet.com/searchVehicles.ajax . 未捕获错误:XmlRenderEngine =>未知错误bundle.js:1 XMLHttpRequest无法加载http://www.erikschevrolet.com/searchVehicles.ajax Origin null is not allowed by Access-Control-Allow-Origin. Access-Control-Allow-Origin不允许使用null。
Uncaught Error: XmlRenderEngine = >Unknown error bundle.js:1 未捕获错误:XmlRenderEngine =>未知错误bundle.js:1

These Chrome warnings are not relevant here. 这些Chrome警告与此无关。 Errors given above are about cross-origin issues. 上面给出的错误是关于跨源问题。 Due to really evil things in which accessing remote resources from within Javascript can result, modern browsers block them unless explicitely allowed. 由于在Javascript中访问远程资源的真正邪恶的东西可能导致现代浏览器阻止它们,除非明确允许。

For example, most content from http://example.com can't be accessed by javascript under http://example.net domain. 例如,来自http://example.com的大多数内容无法通过http://example.net域下的javascript访问。 Since you downloaded most files and you are trying to run them locally, but still some of them refer to files under the http://www.erikschevrolet.com domain, it's not allowed. 由于您下载了大多数文件并且您尝试在本地运行它们,但其中一些文件仍然引用http://www.erikschevrolet.com域下的文件,因此不允许这样做。

AFAIK there isn't a really simple way to avoid this issue; AFAIK没有一种非常简单的方法来避免这个问题; the safest solution would make you download all the used files and manually change references to http://www.erikschevrolet.com with references to your local path. 最安全的解决方案是让您下载所有使用过的文件,并通过引用本地路径手动更改对http://www.erikschevrolet.com的引用。 Alternatively, one can set the withCredentials value of XMLHttpRequest to true (but since you're not a programmer, you can really mess it up...) like this (example from http://hacks.mozilla.org/2009/07/cross-site-xmlhttprequest-with-cors/ ): 或者,可以将XMLHttpRequest的withCredentials值设置为true(但由于你不是程序员,你可以把它弄得一团糟......)就像这样(例如来自http://hacks.mozilla.org/2009/07 / cross-site-xmlhttprequest-with-cors / ):

var request = new XMLHttpRequest();
var url = 'http://bar.other/resources/credentialed-content/';
function callOtherDomain(){
  if(request)
  {
   request.open('GET', url, true);
   request.withCredentials = "true";
   request.onreadystatechange = handler;
   request.send();
  }
}

And even this might not get the expected result as a lot of these files are probably generated dynamically on server and are subject to change. 即使这可能也不会得到预期的结果,因为很多这些文件可能是在服务器上动态生成的,并且可能会发生变化。

It seems that you have a problem in reading an xml or text files in javascript with specific load files scheme. 您似乎在使用特定的加载文件方案在javascript中读取xml或文本文件时遇到问题。 it happens in browsers where requests of http works, here in this case you can try out something like working in javascript, 它发生在http请求工作的浏览器中,在这种情况下你可以试试像在javascript中工作的东西,

if (window.XMLHttpRequest)
    {// code for IE7+, Firefox, Chrome, Opera, Safari
    xmlhttp=new XMLHttpRequest();
    }
else
  {// code for IE6, IE5
    xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }

this will act on chrome safari firefox as well try this. 这将作用于chrome safari firefox以及试试这个。

暂无
暂无

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

相关问题 Javascript无法在浏览器中运行? (Firefox,Chrome和Safari) - Javascript not working in browser? (Firefox, Chrome and Safari) For循环中的Javas If语句可在Chrome和Safari中运行,但不能在Firefox中运行 - Javascript If statement in a For loop working in Chrome and Safari but not Firefox Javascript未在Firefox上执行,适用于Chrome和Safari - Javascript not executed on Firefox, working on Chrome & Safari 可以在Chrome中正常工作的JavaScript jQuery代码,而不能在Firefox,Safari,IE中运行 - Simply javascript jQuery code working in Chrome, not Firefox, Safari, IE Javascript / jQuery无法在Firefox,Safari和IE中运行。 精通Opera和Chrome - Javascript/jQuery not working in Firefox, Safari and IE. Fine in Opera and Chrome Javascript / JQuery突然在Chrome和Firefox中停止工作,但仍在Safari中工作 - Javascript/JQuery suddenly stops working in Chrome and Firefox, but still works in Safari Javascript(JS)应用程序可在Chrome上运行,但不能在mozilla firefox / safari上运行 - Javascript (JS) application working on Chrome but not on mozilla firefox/safari JavaScript代码仅在Chrome中有效,而在Firefox,IE,Opera和Safari中无效 - JavaScript code working only in Chrome but not in Firefox, IE, Opera and Safari JavaScript Ajax请求无法在Firefox和Google Chrome中运行,但在Safari中可以 - JavaScript Ajax request not working in Firefox and Google Chrome, but it is okay in Safari Javascript 表单验证代码适用于 FireFox 和 Chrome,但不适用于 Safari(在单选按钮上) - Javascript form validation code working on FireFox and Chrome but not on Safari (on radio button)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM