About JavaScript in IE Firefox compatibility details (1/4)

Source: Internet
Author: User

* Following IE instead of Internet Explorer to Mf/ff instead of Mozzila Firefox/

Window.event
ie: there are window.event objects
FF: no Window.event object. You can pass an event object to a parameter of a function. such as Onmousemove=domousemove (event)
Workaround: var event = Event | | window.event;
Example
The code is as follows:
<script>
function test (event) {
var event = Event | | window.event;
Do something
}
</script>
<input type= "button" value= "click" onclick= "Test (event)"/>


Mouse Current coordinates
Ie:event.x and Event.y.
Ff:event.pagex and Event.pagey.
General: Both have Event.clientx and Event.clienty attributes.

The current coordinates of the mouse (plus the distance the scroll bar rolls over)
Ie:event.offsetx and Event.offsety.
Ff:event.layerx and Event.layery.
Workaround:
The code is as follows:

<script>
function test (event) {
var event = Event | | window.event;
or var event = event? event:window.event;//can be in this 2, or you can use if else (this shorthand)
var x = Event.offsetx | | Event.layerx;
var y = event.offsety | | Event.layery;
Do something
}
</script>
<div onmousedown= "Test (event)" ></div>

/** other compatible solutions are similar, no more than one by one examples **/

Event.srcelement problem
Description: Under IE, the event object has a srcelement attribute, but there is no target attribute; Firefox, the even object has the target attribute,
However, there is no srcelement attribute.
Workaround: Use obj (obj = event.srcelement? event.srcelement:event.target;)
To replace the event.srcelement under IE or
Firefox under the Event.target. Please also note the compatibility issue of event.

Event.toelement problem
Problem:
Under IE, the even object has a srcelement attribute, but no target attribute;
Firefox, the even object has the target attribute, but there is no srcelement property
Workaround:
var target = E.relatedtarget | | E.toelement;

home 1 2 3 4 last page

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.