我遇到了一个相当奇怪的行为——我的 RequireJS 模块在 IE9 下似乎根本没有初始化和运行:
<head>
...
<script data-main="/static/js/main" src="/static/js/libs/require.js"></script> // Seems to be not running at all.
</head>
但是,每当我启动 IE9 的开发人员工具并重新加载页面时,模块都将正常运行,就像它们在 Firefox/Chrome/Safari 等中应该运行的那样。清理浏览器缓存并关闭 IE9 中的开发者工具将导致 JavaScript 再次完全无法运行。
启动 RequireJS 模块执行的另一种方法是在它之前添加一个同步脚本调用:
<head>
...
<script type="text/javascript" src="https://getfirebug.com/firebug-lite.js"></script> // Add any synchronous script calling here and the module below will execute fine.
<script data-main="/static/js/main" src="/static/js/libs/require.js"></script>
</head>
看起来奇怪行为的原因可能是:
- RequireJS 的异步加载出了点问题
- 出现错误导致脚本在 $.ready() 之前启动
不过,为什么开发者工具可以启动执行确实让我感到困惑。
寻找对该现象的完整解释以及解决方法。
最佳答案
找到答案:console
is undefined
in IE9 when dev tool is not opened,但你永远不会看到这个错误,因为工具的控制台需要重新加载页面开始工作。
关于javascript - RequireJS 在 IE9 中不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12746119/