RequireJS无法在IE9中运行 [英] RequireJS not working in IE9
问题描述
我遇到了一种相当特殊的行为 - 我的RequireJS模块似乎没有在IE9下初始化和运行:
I'm experiencing a fairly peculiar behavior - my RequireJS modules seem to be not initializing and running at all under 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无法再次完全运行。
However, whenever I fire up IE9's developer tool, and reload the page, the modules will be running fine just as they should in Firefox/Chrome/Safari/etc. Cleaning browser cache and closing the developer tool in IE9 will render the JavaScript not running entirely again.
另一种启动RequireJS模块执行的方法是添加一个同步脚本在它之前调用:
Another way to kick-start the execution of the RequireJS modules is to add a synchronous script calling before it:
<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>
看起来奇怪行为的原因可能是:
It would appear that the reason of the weird behavior may either be:
- RequireJS'异步加载出了问题
- 导致脚本在$ .ready()之前启动出错了li>
- Something went wrong with RequireJS' async loading
- Something went wrong that caused scripts to launch before $.ready()
为什么开发人员工具可以启动执行工作真的让我感到困惑。
Why the developer tool can kick-start the execution really baffled me, though.
寻找这个现象的完整解释以及如何解决它。
Looking for a full explanation to the phenomenon and how to solve it.
推荐答案
找到答案:是
未定义
但是你永远不会看到这个错误,因为该工具的控制台需要重新加载页面开始工作。
Found the answer: console
is undefined
in IE9 when dev tool is not opened, but you never get to see this error since the tool's console requires a page reload to start working.
此处有更多详情: https ://github.com/jrburke/requirejs/issues/488
这篇关于RequireJS无法在IE9中运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!