Use event object in Netscape

Source: Internet
Author: User

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.

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.