jQuery 和浏览器兼容性
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5616618/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
jQuery and Browser Compatibility
提问by Jonathan Wood
Yikes! I've been a developer for many years and have always tried to emphasize code that is compatible with as many systems as possible.
哎呀!我已经做了多年的开发人员,并且一直试图强调与尽可能多的系统兼容的代码。
Recent, I purchased the book jQuery in Actionand started reading it. I am very disturbed by the fact that the included source code doesn't appear to work correctly on either of the browsers on my current computer.
最近,我购买了jQuery in Action一书并开始阅读。我对包含的源代码在我当前计算机上的任一浏览器上似乎都无法正常工作这一事实感到非常不安。
Specifically, I downloaded the book's source codeand selected the "jQuery Selectors Lab" for Chapter 2. But it doesn't look how it does in the book.
具体来说,我下载了本书的源代码,并为第 2 章选择了“jQuery Selectors Lab”。但它并没有在书中看到它的表现。
On Google Chrome, both the DOM Sample and DOM Sample Code panes are completely empty. On IE7, things appear much closer to how they appear in the book. But the source code in the DOM Sample Code pane is all on one line (which extends to the right, off the page). Note that the screenshots in the book are of a browser running on the Mac.
在 Google Chrome 上,DOM 示例和 DOM 示例代码窗格都是完全空白的。在 IE7 上,事情看起来更接近于它们在书中的显示方式。但是 DOM Sample Code 窗格中的源代码都在一行上(向右延伸,离开页面)。请注意,本书中的屏幕截图是在 Mac 上运行的浏览器。
I'm curious what sort of cross-browser compatibility users more experienced with jQuery are finding, and what this revelation means for developers who like to be as compatible as possible and are planning to use jQuery.
我很好奇对 jQuery 更有经验的用户正在寻找什么样的跨浏览器兼容性,以及这个启示对于喜欢尽可能兼容并计划使用 jQuery 的开发人员意味着什么。
回答by Hussein
jQuery is actively supported in all these browsers:
所有这些浏览器都积极支持 jQuery:
- Firefox 2.0+
- Internet Explorer 6+
- Safari 3+
- Opera 10.6+
- Chrome 8+
- 火狐 2.0+
- 浏览器 6+
- 野生动物园 3+
- 歌剧 10.6+
- 铬 8+
There are known problems with outdated browsers as per the list below:
根据以下列表,过时的浏览器存在已知问题:
- Mozilla Firefox 1.0.x
- Internet Explorer 1.0-5.x
- Safari 1.0-2.0.1
- Opera 1.0-9.x
- Konqueror
- 火狐浏览器 1.0.x
- Internet Explorer 1.0-5.x
- Safari 1.0-2.0.1
- 歌剧 1.0-9.x
- 征服者
jQuery generally works with Konqueror and Firefox 1.0.x, but there may be some unexpected bugs since we do not test them as regularly.
jQuery 通常适用于 Konqueror 和 Firefox 1.0.x,但可能会出现一些意外错误,因为我们没有定期测试它们。
If you are using any of the outdated browsers, then this could be your problem, otherwise, you should post your code here on stackoverflow to get help. It may not be the browser causing the problem, but it could be the way code is written or executed.
如果您使用的是任何过时的浏览器,那么这可能是您的问题,否则,您应该在 stackoverflow 上发布您的代码以获得帮助。可能不是浏览器导致了问题,但可能是编写或执行代码的方式。
回答by John Slegers
Version 3 of jQuery is maintained for the following desktop browsers :
jQuery 的第 3 版是为以下桌面浏览器维护的:
- Chrome:(Current - 1) and Current
- Edge:(Current - 1) and Current
- Firefox:(Current - 1) and Current
- Internet Explorer:9+
- Safari:(Current - 1) and Current
- Opera:Current
- Chrome:(当前 - 1)和当前
- 边缘:(当前 - 1)和当前
- Firefox:(当前 - 1)和当前
- 浏览器:9+
- Safari:(当前 - 1)和当前
- 歌剧:当前
It is also maintained for the following mobile browsers :
它还为以下移动浏览器维护:
- Stock browser on Android 4.0+
- Safari on iOS 7+
- Android 4.0+ 上的股票浏览器
- iOS 7+ 上的 Safari
Source : https://jquery.com/browser-support/
回答by mu is too short
I think part of your problem is that you're accessing something from the file system that is meant to be loaded from a web server. For example, I see this error in Chome on your chapter 2 example:
我认为您的部分问题是您正在访问文件系统中的某些内容,该文件系统旨在从 Web 服务器加载。例如,我在第 2 章示例的 Chome 中看到此错误:
XMLHttpRequest cannot load file://...chapter2/dom.sample.html.
Origin null is not allowed by Access-Control-Allow-Origin.
Things seem to be behaving reasonably well in Chrome other than that sort of thing.
除了那种事情之外,Chrome 中的事情似乎表现得相当好。
I usually target IE[789], Chrome, Firefox, Safari, and Opera and I haven't seen many browser issues that are specific to jQuery or jQuery-UI. The problems are mostly CSS issues and certain JavaScript problems (in IE for both) that aren't jQuery problems.
我通常针对 IE[789]、Chrome、Firefox、Safari 和 Opera,但我没有看到许多特定于 jQuery 或 jQuery-UI 的浏览器问题。问题主要是 CSS 问题和某些不是 jQuery 问题的 JavaScript 问题(在 IE 中)。
回答by William W. Doyle
I wouldn't be overly worried about the cross-browser compatibility of jQuery so much as I would the quality of the code in the case of this book. I haven't personally looked at this book so I can't make a personal judgement; however, I am the lead developer for a web application that currently has around 15,000 users and we have been confidently using jQuery for a couple of years now with no issues. We have to support customers on a number of platforms using all of the major browsers that are on the market. When jQuery code is written properly and tested for all environments, it can absolutely work properly regardless of what browser you are using.
我不会过分担心 jQuery 的跨浏览器兼容性,就像我会担心本书的代码质量一样。我没有亲自看过这本书,所以我无法做出个人判断;但是,我是目前拥有大约 15,000 名用户的 Web 应用程序的首席开发人员,我们已经自信地使用 jQuery 几年了,没有出现任何问题。我们必须使用市场上所有主要浏览器在多个平台上为客户提供支持。当正确编写 jQuery 代码并针对所有环境进行测试时,无论您使用哪种浏览器,它都绝对可以正常工作。
回答by joohwan
I don't know why but if I copy whole example directory to the tomcat/webapps, it works fine. But if I open page (lab.selectors.html) directly from the browser, it doesn't display dom sample section. The error message from the firefox console was like this:
我不知道为什么,但是如果我将整个示例目录复制到 tomcat/webapps,它就可以正常工作。但是如果我直接从浏览器打开页面 (lab.selectors.html),它不会显示 dom 示例部分。来自 firefox 控制台的错误消息是这样的:
[16:56:36.335] junk after document element @ file:///C:/JavaScript/jqia2/chapter2/dom.sample.html:2
[16:56:36.335] 文档元素@file:///C:/JavaScript/jqia2/chapter2/dom.sample.html:2 之后的垃圾
回答by Daniel Protopopov
Code samples appear to use outdated jQuery v1.4. Download latest version and check known issuesfor more details about cross-browser compatibility.
代码示例似乎使用过时的 jQuery v1.4。下载最新版本并检查已知问题以获取有关跨浏览器兼容性的更多详细信息。