In IE, it is very simple to use the event object. You can call it directly, but in Netscape (NS) and FireFox (FF), it will not achieve the expected results. As shown in the following example, a dialog box is displayed, showing the abscissa of the mouse pointer, but it does not work in NS and FF.
<Html>
<Head>
<Meta http-equiv = "Content-Type" content = "text/html; charset = gb2312">
<Title> Use event objects in Netscape </title>
</Head>
<Body>
<Div>
<A href = "http://www.cftea.com/" target = "_ blank"> Qianyi network http://www.cftea.com/professional discussion [ASP, JavaScript, XHTML + CSS, SQL Server] </a>
<Hr>
</Div>
Click in the blank space
<Script type = "text/javascript" language = "javascript">
<! --
Function Foo ()
{
Alert ("the abscissa of the current mouse pointer is:" + event. clientX );
}
Document. body. onclick = Foo;
-->
</Script>
</Body>
</Html>
There are now two ways to make the program compatible.
<Html>
The second is to pass the event as a parameter. See the example below:
<Head>
<Meta http-equiv = "Content-Type" content = "text/html; charset = gb2312">
<Title> Use event objects in Netscape </title>
</Head>
<Body onclick = "javascript: Foo ();">
<Div>
<A href = "http://www.cftea.com/" target = "_ blank"> Qianyi network http://www.cftea.com/professional discussion [ASP, JavaScript, XHTML + CSS, SQL Server] </a>
<Hr>
</Div>
Click in the blank space
<Script type = "text/javascript" language = "javascript">
<! --
Function Foo ()
{
Var theEvent = window. event | arguments. callee. caller. arguments [0];
Alert ("the abscissa of the current mouse pointer is:" + theEvent. clientX );
}
-->
</Script>
</Body>
</Html>
The second is to pass the event as a parameter. See the example below:
<Html>
<Head>
<Meta http-equiv = "Content-Type" content = "text/html; charset = gb2312">
<Title> Use event objects in Netscape </title>
</Head>
<Body onclick = "javascript: Foo (event);">
<Div>
<A href = "http://www.cftea.com/" target = "_ blank"> Qianyi network http://www.cftea.com/professional discussion [ASP, JavaScript, XHTML + CSS, SQL Server] </a>
<Hr>
</Div>
Click in the blank space
<Script type = "text/javascript" language = "javascript">
<! --
Function Foo (e)
{
Alert ("the abscissa of the current mouse pointer is:" + e. clientX );
}
-->
</Script>
</Body>
</Html>
Note: in both methods, the method for calling a function is no longer document. body. onclick = Foo.