开发者

DD_belatedPNG without editing the markup

I'd like to use DD_bela开发者_JAVA百科tedPNG for a project, but I'm not allowed to edit the markup to add the following conditional comment that is required for the script to function:

<!--[if IE 6]>
<script src="DD_belatedPNG.js"></script>
<script>
  /* EXAMPLE */
  DD_belatedPNG.fix('.png_bg');

  /* string argument can be any CSS selector */
  /* .png_bg example is unnecessary */
  /* change it to what suits you! */
</script>
<![endif]-->

I'm already using jQuery on this project and I can also detect IE, so I wonder if its possible to place the DD_belatedPNG.fix(); function inside my $(document).ready()? Would it work?


You need to check jQuery.browser, like so:

$(document).ready (function () {
    if ($.browser.msie && $.browser.version < 7)
        $.getScript ('DD_belatedPNG.js', DD_belatedPNG.fix);
});

This will load the external JS file for DD_belatedPNG as well, and call the fix method once loaded


Yes, it would. Using $(document).ready(), or the shortcut $(function() {}, has the same effect than adding the conditional comment.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜