如果浏览器是IE 6 7 8 9FirefoxSafariChrome或Opera
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了如果浏览器是IE 6 7 8 9FirefoxSafariChrome或Opera相关的知识,希望对你有一定的参考价值。
The html simply discovers if it's IE and its version or if it's not IE.The jQuery discovers if it's IE, Firefox, Webkit Engine (Chrome and Safari) or Opera and its version as an integer.
<!--[if lt IE 7 ]> <html lang="en" class="no-js ie6"> <![endif]--> <!--[if IE 7 ]> <html lang="en" class="no-js ie7"> <![endif]--> <!--[if IE 8 ]> <html lang="en" class="no-js ie8"> <![endif]--> <!--[if gte IE 8]> <html lang="en" class="no-js ie9"> <![endif]--> <!--[if !IE]><!--> <html lang="en" class="no-js"> <!--<![endif]--> <head> <title></title> <script src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js" type="text/javascript" ></script> <style type="text/css" media="screen"> html { background: green; } html.ie7 { background: blue; } html.ie8 { background: yellow; } html.ie9 { background: red; } </style> <script type="text/javascript" > $(document).ready(function(){ if ( $.browser.msie ) { alert( 'This is a Microsoft Internet Explorer ' + $.browser.version.substr(0, 1) ); } else if ( $.browser.mozilla ) { alert( 'This is a Mozilla Firefox ' + $.browser.version.substr(0, 1) ); } else if ( $.browser.webkit || $.browser.safari ) { alert( 'This is a Webkit Engine Browser (Apple Safari or Google Chrome) with version ' + $.browser.version.substr(0, 1) ); } else if ( $.browser.opera ) { alert( 'This is an Opera ' + $.browser.version.substr(0, 1) ); } }) </script> </head> <body> <p> default: green <br/> ie7: blue <br/> ie8: yellow <br/> ie9: red </p> </body> </html>
以上是关于如果浏览器是IE 6 7 8 9FirefoxSafariChrome或Opera的主要内容,如果未能解决你的问题,请参考以下文章
addEventListener attachEvent和解决IE 6 7 8 this指向错误
如何用JS捕捉 浏览器关闭事件,我想在浏览器关闭的时候记录一些日志。要兼容Firefox和IE 6、7、8 !3Q....