开发者

How to write browser related script using jQuery?

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜