开发者

Why my jquery code works in IE9 but not in IE8?

开发者 https://www.devze.com 2023-04-07 19:16 出处:网络
<script> $(document).ready(function() { $(\"#various2\").fancybox({ \'width\': 800, \'height\': 570,
<script>
            $(document).ready(function() {
                $("#various2").fancybox({
                    'width': 800,
                    'height': 570,
                    'type':'iframe'
                });
            });
</script>

I'm getting error in IE8 and 7 but not in IE9

Object doesn't support property or method 'fancybox'

and error is on this line

$("#various2").fancybox({

and my scripts are at bottom before &开发者_开发知识库lt;/body>

<script src="//ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.min.js" defer="defer"></script>
        <script>!window.jQuery && document.write(unescape('%3Cscript src="js/libs/jquery-1.5.1.min.js"%3E%3C/script%3E'))</script>
        <script src="js/plugins.js" defer="defer"></script>
        <script>
        $(document).ready(function() {
            $("#various2").fancybox({
                'width': 800,
                'height': 570,
                'type':'iframe'
            });
        });
        </script>


You are using defer on the jQuery library, which means it is probably not getting loaded before the jQuery code itself.

Since your scripts are at the bottom of the page before </body> there is no need to defer loading them at all since the rest of the page had already loaded.


I guess, you should debug around defer="defer" part. Different IE versions may be interpreting it different way, causing js libs to be parsed after body script gets parsed.


Inline script tags don't support defer, and so will always execute as soon as they are encountered. Because your external script has defer, it will load at some arbitrary point in the future. Thus, your inline script will (almost) always execute before your external script has downloaded and run.

0

精彩评论

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

关注公众号