Use or | to be compatible with FireFox_JavaScript

Source: Internet
Author: User
Use or | to be compatible with FireFox Example:

Run code box
<! DOCTYPE html PUBLIC "-// W3C // dtd xhtml 1.0 Transitional // EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <ptml xmlns = "http://www.w3.org/1999/xhtml"> <pead> <meta http-equiv =" content-Type "content =" text/html; charset = UTF-8 "/> <title> Untitled Document </title> </pead> <body> <li> open </li> <li> open </li> </body> </ptml> <script language = "javascript" type = "text/javascript"> document. body. onclick = function (evt) {evt = evt | window. event; var o = evt.tar get | evt. srcElement; window. open (o. previussibling. href | o. previussibling. previussibling. href); return false;} script
[Ctrl + A select all tips: you can modify some code and then press run]

Find document. body. onclick = function (evt ),
In IE, this evt does not exist, but in fireFox (it seems like it is also in opera), this parameter is passed by default. in IE, this parameter is null. To be compatible, write it like this.

Continue down:
Evt = evt | window. event;
In IE, evt points to window. event. In fireFox, it points to the default parameter.
In IE, evt | window. event is equivalent to: null | window. event. The result is still window. event.
In fireFox, the result is evt | null.

Look down:
O. previussibling. href | o. previousSibling. previousSibling. href
The first expression is used for IE, and the other one is used for FireFox.
In FireFox, there is no preserveWhiteSpace attribute, that is, blank space is treated as a node, while in IE, the default value is false, that is, blank space is not considered as a node.

XMLDom seems unrelated to the above mentioned, but in FireFox, previussibling is blank unless there is no space between two HTML tags.


Open
There is a line break between the two (a space), so in FireFox, take the previous node of the following, you must use:
O. previussibling. previussibling. href

Maybe you still don't understand, it doesn't matter,Another simple example:

Run code box
Script function test (p1, p2, p3) {p1 = p1 | 100; p2 = p2 | "xlingFairy "; return "p1 =" + p1 + "p2 =" + p2 + "p3 =" + p3;} alert (test (); alert (test (null, null, "blueidea.com") script
[Ctrl + A select all tips: you can modify some code and then press run]

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.