IE and Firefox process event capture differently.
Ie uses the event as an attribute of the window and uses it through the window. Event method. Firefox uses the event object as a parameter of the function to capture the event. Are you confused?
Don't worry. Let's see the following example.
When you click a position on the page, a dialog box is displayed, showing the coordinates of the click point on the screen.
Document. onmousedown = mousedown;
IE:
Function mousedown (){
VaR locstring = "x =" + window. event. screenx + "Y =" + window. event. screeny;
Alert (locstring );
}
In Firefox:
Function mousedown (ffevent ){
VaR locstring = "x =" + ffevent. screenx + "Y =" + ffevent. screeny;
Alert (locstring );
}
Then, in actual scenariosCodeHow to write?
The following code provides a compatibility mode for IE and Firefox, which can be determined by using a ternary operator (Object detection:
Function mousedown (ffevent ){
VaR theevent = ffevent? Ffevent: window. event;
VaR locstring = "x =" + theevent. screenx + "Y =" + theevent. screeny;
Alert (locstring );
}
The complete code for this application is as follows:
<! Doctype HTML public "-// W3C // dtd xhtml 1.0 transitional // en"
Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd>
<HTML>
<Head>
<Title> x/y marks the spot </title>
<Meta http-equiv = "Content-Type" content = "text/html; charset = UTF-8"/>
<SCRIPT type = "text/JavaScript">
// <! [CDATA [
Function mousedown (ffevent ){
VaR theevent = ffevent? Ffevent: window. event;
VaR locstring = "x =" + theevent. screenx + "Y =" + theevent. screeny;
Alert (locstring );
}
Document. onmousedown = mousedown;
//]>
</SCRIPT>
</Head>
<Body>
</Body>
</Html>
Logistics Distribution Network http://wlphw.com/QQ online: 471226865