Differences between JS Code in IE and Firefox (Continuous updates)

Source: Internet
Author: User

1. Question about the ID of an HTML object as the object name
IE: the ID of the HTML object can be directly used as the variable name of the subordinate object of the document.
FF: not supported
Solution: Use document. getelementbyid to replace document. All.

2. If the control only has name and no ID, when getelementbyid is used:
IE: the object can be found.
FF: NULL is returned.
Solution: The ID attribute must be set for all controls.

3. Evel:
IE: Yes. You can use eval (idname) to obtain the HTML object with ID as idname.
FF: not supported.
Solution: Use getelementbyid (idname) instead of eval (idname ).

4. event:
IE: Use the Global Object window. Event
FF: the event can only be used when an event occurs. The event object is input when a function is called.
Solution: Make browser type judgments before using them.

5. replace '$' with the underscore '_' in the object name '_'

6. Collection class Object Problems
IE: You can use () or [] to obtain collection class objects.
FF: Only [] can be used to obtain collection class objects.
ExistingCodeAnd cannot run in ff.
Solution: use [] to retrieve collection class objects. The statement such as document. Form. Item ("itemname") is changed to document. Form. elements ["elementname"]

7. The variable name is the same as the ID of an HTML object.
IE: you cannot use the same variable name as the HTML Object ID.
FF: available
Solution: When declaring variables, add VaR to avoid ambiguity, so that it can run normally in IE.
In addition, it is best not to take the same variable name as the HTML Object ID to reduce errors.

8. Event locating
IE: supports event. X and event. Y.
FF: supports event. pagex and event. Pagey.
Solution: Use event. clientx and event. clienty, but event in ff. clientx and event. pagex has a subtle difference (when the entire page has a scroll bar), but most of the time it is equivalent. To be exactly the same, you can determine the browser type and use it accordingly.

9. parent node Problems
IE: parentelement. Children
FF: parentnode. childnodes
Childnodes has different meanings in IE and ff. FF inserts blank text nodes in childnodes using Dom standards. You can avoid this problem by using node. getelementsbytagname.

When a node in HTML is missing, ie and FF have different interpretations of parentnode, for example
<Form>
<Table>
<Input/>
</Table>
</Form>
IE: The input. parentnode value is an empty node.
FF: the value of input. parentnode is form.
The node in FF does not have the removenode method. You must use the following method: node. parentnode. removechild (node)

10. Const Problems
Existing problems:
IE: the const keyword is not supported. For example, const constvar = 32; in IE, This Is A syntax error.
FF: supported
Solution: use VaR instead of Const.

11. Body object
IE: it exists only after the body tag is fully read.
FF: It exists before the body tag is completely read by the browser.

12. Custom Attributes
IE: You can use the method to obtain general attributes to obtain custom attributes, or you can use getattribute () to obtain custom attributes.
FF: You can only use getattribute () to obtain custom attributes.
Solution: getattribute () is used to obtain custom attributes.

13. event. srcelement Problems
IE: Even. srcelement
FF: even.tar get
Solution: Determine the browser type during use.

14. Modal and non-modal windows
IE: supports modal and non-modal windows
FF: not supported
Solution: Use window. Open (pageurl, name, parameters) to open a new window. If you want to pass the parameters in the Child window back to the parent window, you can use window. opener in the Child Window to access the parent window.

15. innertext
IE: innertext
FF: textcontent

16. statements similar to OBJ. style. Height = imgobj. Height
IE: VALID
FF: Invalid
Solution: Use obj. style. Height = imgobj. height + 'px ';

 

This article is from the csdn blog. For more information, see http://blog.csdn.net/nileel/archive/2009/08/19/4461687.aspx

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.