开发者

How to write browser related script using jQuery?

开发者 https://www.devze.com 2022-12-28 20:12 出处:网络
How do I target different browsers using jQuery? For e开发者_运维知识库xample the javascript for IE6 and IE7 needs to be different.You can check for different browsers like this:

How do I target different browsers using jQuery? For e开发者_运维知识库xample the javascript for IE6 and IE7 needs to be different.


You can check for different browsers like this:

if($.browser.msie && $.browser.version === 6)


Well, you could use conditional comments to include your scripts, like this perhaps:

<!--[if IE 6]>
<script type="text/javascript" src="http://www.example.com/js/ie6.js"></script>
<![endif]-->

This would be great if you wanted to target entire files at each browser, without having to send all the scripts down to each browser and then check.

Alternatively one of the other answers (at this time) tells you how to do it on a smaller scale.


I'd suggest reading about feature detection. http://peter.michaux.ca/articles/feature-detection-state-of-the-art-browser-scripting wouldn't be a bad starting place.


jQuery aims at cross-browser-compatibility, so usually there is no need to write different javascript for specific browsers. use the function provided my jQuery (or therefor any other javascript framework like mootools) and you shouldn't have any problems

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号