Differences between JavaScript, IE and non-IE (to be continued)

Source: Internet
Author: User
VarisIEnavigatoruserAgenttoLowerCase () indexOf (& quot; msie & quot;) & gt;-1? True: false; varisIE9msies + 9 itest (navigatoruserAgent); 1 floatif (isIE) {documentgetElementById (
Var isIE = navigator. userAgent. toLowerCase (). indexOf ("msie")>-1? True: false; var isIE9 =/msie \ s + 9/I. test (navigator. userAgent); // 1. floatif (isIE) {document. getElementById ("block "). style. styleFloat = "right";} else {document. getElementById ("block" ).style.css Float = "right";} // 2. the calculated style if (isIE) {var currentStyle = document. getElementById ("block "). currentStyle. backgroundColor; console. log (currentStyle);} else {var dom = document. getElementById ("block"); var currentStyle = document. defaultView. getComputedStyle (dom, null ). backgroundColor; console. log (currentStyle);} // 3. obtain the cursor position if (isIE) {var dom = document. getElementById ("block"); dom. onmouseover = function (event) {if (isIE9) {console. log (event. pageX); return;} event = event | window. event; console. log (event. clientX) ;}} else {var dom = document. getElementById ("block"); dom. onmouseover = function (event) {console. log (event. pageX) ;}// 4. obtain the size of a window or browser window if (isIE) {var browerSize ={}; browerSize. screenX = document.doc umentElement. clientWidth; browerSize ['screeny'] = document.doc umentElement. clientHeight; console. log (browerSize);} else {var browerSize = {}; browerSize. screenX = window. innerHeight; browerSize ['screeny'] = window. innerWidth;} // 5. register event if (isIE) {var elem = document. getElementById ("hit"); elem. attachEvent ("onclick", function (event) {event = event | window. event; // event source console. log (event. srcElement); // event propagation event. cancelBubble = true; // block the default event. returnValue = false ;}) ;}else {var elem = document. getElementById ("hit"); elem. addEventListener ("click", function (event) {// event source lele.log(event.tar get & event. srcElement); // event propagation event. stopPropagation (); // block the default event. preventDefault () ;}, false) ;}// 6. obtain the parent object in the object level, IE: parentElementvar parent = function (elem) {elem = document. getElementById (elem); return elem. parentElement & elem. parentNode;} // 7. obtains the HTML element and the TextNode object set var getChildren = function (elem) {elem = document. getElementById (elem); return elem. childNodes & elem. children;} // 8. DOM loaded. if (isIE) {document. attachEvent ("onreadystatechange", function () {console. log ("ie dom ready") ;}} else {document. addEventListener ("DOMContentLoaded", function () {console. log ("Webkit DOM ready") ;}, false );}

 

Related Article

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.