JS with or | | To be compatible with firefox!_javascript techniques

Source: Internet
Author: User
<textarea id="runcode91822"><! 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 </l i> <li> Open </li> <li> open </li> </body> </ptml> <script language= "ja Vascript "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></textarea>
[Ctrl + A All SELECT Note: If the need to introduce external JS need to refresh to perform]

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 downward,
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

Next look:
O.previoussibling.href | | O.previoussibling.previoussibling.href
The previous expression is used under IE, and the latter one is used under Firefox.
Because in IE, XMLDOM did not preservewhitespace this attribute, namely: The blank also as a node, and IE defaults to false, that is, the white space is not regarded as 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= "http://www.jb51.net/article/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 understand, it doesn't matter, in a simple:
<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 Note: If the need to introduce external JS need to refresh to perform]

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.