IE上开发的Javascript的典型原因是什么? [英] What are the typical reasons Javascript developed on IE fails on Firefox?
问题描述
我经常遇到的问题与这篇文章。也就是说,我已经在仅为Internet Explorer设计的遗留应用程序中提供了代码,我需要让它在Firefox中工作。
I often suffer from the problem opposite what's described in this post. That is, I've got code in a legacy application designed only for Internet Explorer and I need to get it to work in Firefox.
例如,我最近在一个大量使用手动模拟点击事件的应用程序,如下所示:
For example, I recently worked on an app that made heavy use of manually simulating click events, like this:
select.options[0].click();
...完全打破了Firefox中的应用程序。但是你不会在另一个问题的答案中找到这些信息,因为如果您的应用程序首先定位到Firefox,那么您甚至不会尝试。
...which completely broke the application in Firefox. But you wouldn't find that information in the answers to the other question, because that's not something you'd ever even attempt if your app first targeted Firefox.
其他什么迁移到现代浏览器时,开发人员应该更新旧版IE浏览器吗?
What other things should a developer updating a legacy IE-only application look for when migrating to modern browsers?
推荐答案
以下是我以前的研究发现。我已经看到这些问题阻止了真实世界的应用程序在Firefox中工作。请自由编辑。
Here's what my previous research uncovered. I've seen each of these issues prevent a real-world application from working in Firefox. Please feel free to edit.
document.createElement
应该只使用一个标签名称,但IE可以让
传递任意的HTML(带有属性等)
document.createElement
should take only a tag name, but IE lets you
pass arbitrary HTML (with attributes, etc)
- http://msdn.microsoft.com/en-us/library/ms536389(VS.85).aspx
document.getElementById
只能找到给定的 id
,
的元素,但IE也返回给定的元素名称
- http://msdn.microsoft.com/en-us/library/ms536437(VS.85).aspx
IE为DOM元素创建隐式全局变量,但是在Firefox中引用一个元素会产生以下警告:
IE creates implicit global variables for DOM elements, but referencing an element this way in Firefox produces the following warning:
Eleme在
全局范围内由ID / NAME引用。使用W3C标准
document.getElementById()。
"Element referenced by ID/NAME in the global scope. Use W3C standard document.getElementById() instead."
- http://www.west-wind.com/weblog/posts/677442.aspx
- http:// code .google.com / p / fbug / issues / detail?id = 853
- http://www.west-wind.com/weblog/posts/677442.aspx
- http://code.google.com/p/fbug/issues/detail?id=853
- < a href =http://msdn.microsoft.com/en-us/library/ms537434(v=vs.85).aspx =nofollow noreferrer> http://msdn.microsoft.com/en- us / library / ms537434(v = vs85).aspx
- http://msdn.microsoft.com/en-us/library/ms537434(v=vs.85).aspx
- http://msdn.microsoft.com/en-us/library/ms533899(v=vs.85).aspx
- http://msdn.microsoft.com/en-us/library/ms537457(v=VS.85).aspx
- http://msdn.microsoft.com/en-us/library/ms537484%28VS.85%29.aspx
- http://msdn.microsoft.com/en-us/library/ms536457%28VS.85%29.aspx
- https://developer.mozilla.org/en/ DOM / table.insertRow
- http://msdn.microsoft.com/en-us/library/ms536457%28VS.85%29.aspx
- https://developer.mozilla.org/en/DOM/table.insertRow
- http://msdn.microsoft.com/en-us/library/ms534677%28VS.85%29.aspx
- https://developer.mozilla.org/En/DOM/Node。 textContent
- http://msdn.microsoft.com/en-us/library/ms534677%28VS.85%29.aspx
- https://developer.mozilla.org/En/DOM/Node.textContent
- http://msdn.microsoft.com/en-us/library/ms535863(v = vs85).aspx
- http://www.quirksmode。 org / js / events_access.html#link3
- http://msdn.microsoft.com/en-us/library/ms535863(v=vs.85).aspx
- http://www.quirksmode.org/js/events_access.html#link3
- http://msdn.microsoft.com/en-us/library/ms536343(v=vs.85).aspx
- http://msdn.microsoft.com/en-us/library/ms533567(v = vs85).aspx
- http://msdn.microsoft.com/en-us/library/ms533568(v = vs85).aspx
- http://www.quirksmode.org/js/events_properties.html#position
- http://msdn.microsoft.com/en-us/library/ms533567(v=vs.85).aspx
- http://msdn.microsoft.com/en-us/library/ms533568(v=vs.85).aspx
- http://www.quirksmode.org/js/events_properties.html#position
- http://msdn.microsoft.com/en-us/library/ms536363(v = vs85).aspx
- http:// lifescaler。 com / 2008/04 / simulating-mouse-clicks-in-javascript /
- http://www.devtoolshed.com/content/fix-firefox-click-event-issue
- http://msdn.microsoft.com/en-us/library/ms536363(v=vs.85).aspx
- http://lifescaler.com/2008/04/simulating-mouse-clicks-in-javascript/
- http://www.devtoolshed.com/content/fix-firefox-click-event-issue
- Is there a 4096 character limit for JavaScript XML text nodes?
- http://www.w3schools.com/dom/prop_element_firstchild。 asp
- https://developer.mozilla。 org / en / Whitespace_in_the_DOM
- http://www.w3schools.com/dom/prop_element_firstchild.asp
- https://developer.mozilla.org/en/Whitespace_in_the_DOM
- http://www.w3schools.com/dom/prop_node_xml.asp
- http://www.grange.com.br/dicas-tecnicas/40-lotus/345- dom-xml-wrapper-for-javascript
- http://www.w3schools.com/dom/prop_node_xml.asp
- http://www.grange.com.br/dicas-tecnicas/40-lotus/345-dom-xml-wrapper-for-javascript
- http://www.reloco.com.ar/mozilla/compat.html
- https://developer.mozilla.org/en/migrate_apps_from_internet_explorer_to_mozilla
- http://www.impressivewebs。 com / 7-javascript-differences-between-firefox-ie /
- http://www.reloco.com.ar/mozilla/compat.html
- https://developer.mozilla.org/en/migrate_apps_from_internet_explorer_to_mozilla
- http://www.impressivewebs.com/7-javascript-differences-between-firefox-ie/
IE的 document.all
是文档中所有元素的集合,Firefox不支持。
IE's document.all
is a collection of all elements in the document. It is not supported by Firefox.
IE中的元素文本将使用 innerText
属性Firefox调用此属性 textContent
。
An Element's text in IE is retrieved using the innerText
property. Firefox calls this property textContent
.
IE允许使用函数语法引用集合中的项目(即括号),而不是正常的数组索引语法(即括号)。例如,以下工作在IE中: document.forms(0)
。 Firefox不支持这种用法。
IE allows items in collections to be referenced using function syntax (i.e. with parentheses) instead of the normal array indexing syntax (i.e. with brackets). For example, the following works in IE: document.forms(0)
. Firefox does not support this usage.
HTMLTableElement
rows
单元格
应该引用 HTMLCollections
,但
IE允许将其调用为函数; Firefox不支持。
HTMLTableElement
rows
and cells
should refer to HTMLCollections
, but
IE allows them to be called as functions; Firefox does not.
IE默认值 insertRow
的索引
1; Firefox的错误,如果参数被省略。
IE defaults insertRow
's index
to -1; Firefox errors if the argument is omitted.
Node.text
属性是IE-only
The Node.text
property is IE-only
window.event
是访问事件信息的IE特定方式; Firefox不支持
。
window.event
is an IE-specific way to access event information; it's not
supported by Firefox.
事件附加到IE中的元素使用的attachEvent
。 Firefox使用 addEventListener
。请注意,每个浏览器中的事件名称都是微不足道的。
Events are attached to Elements in IE using attachEvent
. Firefox uses addEventListener
. Note, also, that the names of events are subtly different in each browser.
在IE中可以从非鼠标事件获取鼠标位置,但不在其他浏览器。另外,IE和Firefox中鼠标坐标属性的名称不一样。
In IE it's possible to get the mouse position from non-mouse events, but it's not in other browsers. In addition, the names of the mouse-coordinate properties are not the same in IE and Firefox.
IE支持点击
方法触发 onclick
事件在HTML元素上。 Firefox中没有这样的功能。
IE supports a click
method for triggering the onclick
event on HTML elements. No such function exists in Firefox.
Firefox将文本节点分割成4096个字符块; IE没有。这个
意味着IE和Firefox中的 childNodes
之类的东西会有所不同。
Firefox splits text nodes into 4096-char blocks; IE does not. This
means that things like childNodes
will be different in IE and Firefox.
Internet Explorer定义了一个 parseError.errorCode
property on
XMLDocuments用于检测解析器错误。 Firefox加载一个包含文档中错误信息的XML文档,其中包含 documentElement.nodeName ==parsererror
。
Internet Explorer defines a parseError.errorCode
property on
XMLDocuments for detecting parser errors. Firefox loads an XML document that contains error information in the document with documentElement.nodeName=="parsererror"
.
IE忽略XML中的空格; firstChild
总是返回第一个
ELEMENT_NODE
IE ignores whitespace in XML; firstChild
always returns the first
ELEMENT_NODE
Node.xml
属性是IE-only
The Node.xml
property is IE-only
这篇关于IE上开发的Javascript的典型原因是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!