Use or | | To be compatible with Firefox_javascript

Source: Internet
Author: User
Tags html tags

See 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> <a href=" Http://www.blueidea.com/articleimg/bbsimg/smile.gif "/></a> <a href=" picture address > Open </a> </li> <li> <a href= "http://www.blueidea.com/articleimg/bbsimg/biggrin.gif"/></a> <a href= "Picture Address" > Open </a> </li> <li> <a href= "Http://www.blueidea.com/articleimg/bbsimg/confused.gif"/></a > <a href= "Picture address" > Open </a> </li> </body> </ptml> <script language= "javascript" type= " Text/javascript "> Document.body.onclick = function (evt) {evt = evt | | window.event; var o = Evt.target | | Evt.srcelement; window.open (O.previoussibling.href | | o.previoussIBLING.PREVIOUSSIBLING.HREF); return false; } </script>
[Ctrl + A ALL SELECT hint: You can modify some of the code, and then run]

Find Document.body.onclick = function (evt),
In IE, this evt is not, but under the Firefox (opera seems to be) will pass this parameter by default. In IE, this parameter is null, want to be compatible, just write.

Continue down:
EVT = EVT | | window.event;
In IE, EVT will point to: Window.event, under Firefox, will point to that default parameter.
Because under IE evt | | Window.event equivalent to: null | | Window.event, the result is still window.event.
And in Firefox, it's the equivalent of EVT | | NULL, the result is evt

Look down:
O.previoussibling.href | | O.previoussibling.previoussibling.href
The previous expression is used under IE, and the latter one is used under Firefox.
Firefox, there is no preservewhitespace this attribute, namely: The blank also as a node, and IE is the default false, that is, the white space is not considered a node.

Speaking of XMLDOM, it seems to be irrelevant, but under Firefox previoussibling is blank, unless there are no spaces between the two HTML tags.

<a href= "Http://www.blueidea.com/articleimg/bbsimg/smile.gif"/></a>
<a href= "Picture address" > Open </a>
Two <a> there is a newline (one of the spaces), so under Firefox, take the following one <a> the previous node, you must use:
O.previoussibling.previoussibling.href

Maybe you still don't see it, it doesn't matter, just give me a simple one:

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 ALL SELECT hint: You can modify some of the code, and then 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.