The difference between IE and FF in JavaScript

Source: Internet
Author: User

1. Custom attribute problems: You can get custom properties by using methods that get general properties, or you can use Getatribute () to derive a custom attribute, and only use getattribute () to derive a custom attribute under FF.

2. In IE, you can use eval ("Idname") or getElementById ("Idname") to obtain an HTML object with ID idname, which can only be used with the latter, the solution, and unified getElementById acquisition.

The ID of the HTML object under 3.IE can be used directly as the subordinate object variable name of document, but not under FF. FF can use the same variable as the HTML object ID, ie cannot. Workaround: Use document.getElementById ("Idname") instead of document.idname. It is best not to take the same variable name as the HTML object ID to reduce the error, and to declare the variable with VAR to avoid ambiguity.

4.ie Add the Event function addeventlistener,ff add attachevent.

5.event.srcelement problem. In IE, the event object has the Srcelement property, FF under the event (E) object has the target property, the solution: Var obj=event.srcelement?event.srcelement:e.target;

6.event.x and event.y problem, ie under the event object has an X, Y property, but no Pagex,pagey property, FF under the event (E) object has the Pagex,pagey attribute, but does not have the X, Y property. Workaround:

var Myx=event.x?event.x:event.pagex; var Myy=event.y?event.y:event.pagey;

7.window.event problem. Window.event can only be run under IE, not in ff. This is because FF's even (e) can only be used at the site where the event occurred. Solution: Pass in a formal parameter E.

function Dosom (e) {var myevent=e?e: (Window.event?window.event:null)}

8.input.type property issues. The Input.type property under IE is read-only, but the Input.type property under FF is read-write. WORKAROUND: You cannot modify the properties of the Input.type, if you have to modify it, you can first hide the original input and then insert a new INPUT element in the same position.

9.const problem. You can use the Const keyword or the var keyword to define constants under FF, and you can only define constants with the VAR keyword in IE, the solution: use the var keyword definition uniformly.

10,innertext problem, innerText in IE can work normally, but innerText in FF can not, need to use texcontent. innerHTML is supported by Ieff and other browsers, but outerhtml can only be used by IE.

11. Object width and Height assignment problem
Problem Description: A statement similar to obj.style.height = Imgobj.height in Firefox is invalid.
Workaround: Use Obj.style.height = imgobj.height + "px" uniformly;

The difference between IE and FF in JavaScript

Related Article

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.