如何防止“无法获取属性的值”dir':object is null或undefined“在IE9中加载页面时出错 [英] How to prevent "Unable to get value of the property 'dir': object is null or undefined" error when loading pages in IE9

查看:188
本文介绍了如何防止“无法获取属性的值”dir':object is null或undefined“在IE9中加载页面时出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Dojo 1.7.4应用程序,在IE9中加载页面时,无法获得属性'dir'的值:object is null或undefined错误。



我使用的是AMD版本,并且不得不单独加载所有文件时出现错误。



我所控制的所有代码包裹在dojo /准备和dom / domReady!调用了偏执点。



当错误发生时,我抓住IE9调试器,并且调用堆栈显示在调用isBodyLtr时发生错误,但是调用堆栈的顶部是nls / synapse_en-gb.js。 nls / synapse_en-gb.js文件似乎是应用程序使用的所有en-gb翻译的编译nls文件。



这似乎正在加载凭借en-gb作为我dojoConfig中唯一的区域设置条目,我似乎没有控制权,以确保它也包含在dojo / ready或dojo / domReady!中。



这是引导Dojo包的HTML示例代码。



任何指针,用于防止翻译文件运行直到dom和剩余Dojo文件已经完全加载?

 < script type =text / javascript> 
//<![CDATA [
var dojoConfig = {
async:true,
parseOnLoad:true,
isDebug:true,
locale: en-gb,
baseUrl:/ synapse / js / dojo / dojo /,
路径:{synapse:../../synapse}
} ;

//]]>
< / script>
< script type =text / javascriptsrc =/ synapse / js / dojo / dojo / dojo.js>< / script>
< script type =text / javascript>
//<![CDATA [
require(['dojo / ready','synapse / synapse','dojo / domReady!'],function(ready){
ready function(){

require(['dojo / ready','synapse / overlay','dojo / domReady!'],function(ready,package){
ready ){
package.init();
});
});
});
});

//]]>





更新:17 2013年4月
要尝试编写堆栈跟踪中的什么函数调用,我从dojo.js.uncompress.js引导。



这显示了nls / synapse_en-gb.js是入口点,调用 var def = function()(在全局命名空间中以定义,然后 checkComplete ,然后 execModule 等等。 p>

由于这似乎在DOM加载之前运行,我需要找到一种方法来确保在加载DOM之前不会运行nls / synapse_en-gb.js。



查看我生成的突触/ synapse.js,在基地有一个* now函数,似乎预加载i18n文件文件,即

 * now:function(r){
r([dojo / i18n!* preload * synapse / nls / synapse * \\ ar\,\ ca\,\ cs\,\ da\,\ de\,\el\ \ EN-gb\,\ EN-us\,\ ES-es\,\ FI-fi\,\ FR-fr\ \ 他-il\,\ hu\,\ 它-it\,\ JA-jp\,\ KO-kr\ \ NL-nl\,\ nb\,\ pl\,\ PT-br\,\ PT-pt\,\RU \ \ sk\,\ sl\,\ sv\,\ th\,\ tr\,\ ZH-TW \ \ ZH-cn\,\ ROOT\]]);
}

我可能最终不得不重新定位所有的dojo加载,直到有一个

解决方案

我最终不得不移动内联部分的脚本到< / body> 标签之后。


I have a Dojo 1.7.4 app that is getting "Unable to get value of the property 'dir': object is null or undefined" error when loading pages in IE9.

I'm using an AMD build, and the error does not happen when it has to load all the files individually.

All the code that I have control over is wrapped in dojo/ready and dom/domReady! calls to the point of paranoia.

When the error occurs, and I catch it with the IE9 debugger, and Call stack reveals that the error occurs when calling isBodyLtr, but the top of the call stack is nls/synapse_en-gb.js. The nls/synapse_en-gb.js file seems to be the compile nls file with all the en-gb translations used by the application.

This seems to be getting loaded by virtue of having "en-gb" as my only locale entry in my dojoConfig, and I don't seem have control to ensure it is also wrapped in a dojo/ready or dojo/domReady!.

Here is the sample code in my HTML that bootstraps the Dojo package.

Any pointers for preventing the translation file from running until the dom and remaining Dojo files have fully loaded?

<script type="text/javascript">
//<![CDATA[
var dojoConfig = {
async: true,
parseOnLoad: true,
isDebug: true,
locale: "en-gb",
baseUrl: "/synapse/js/dojo/dojo/",
paths: {"synapse": "../../synapse"}
};

//]]>
</script>
<script type="text/javascript" src="/synapse/js/dojo/dojo/dojo.js"></script>
<script type="text/javascript">
//<![CDATA[
require(['dojo/ready', 'synapse/synapse', 'dojo/domReady!'], function(ready) {
ready(function () {

    require(['dojo/ready', 'synapse/overlay','dojo/domReady!'], function (ready, package) {
        ready(function() {
            package.init();
        });
    });
});
});

//]]>

Update: 17 April 2013 To try and work out what function calls are in the stack trace, I bootstrapped from dojo.js.uncompress.js.

This shows me that nls/synapse_en-gb.js is the entry point, with calls to the var def = function() (which gets exposed in the global namespace as define, then checkComplete, then execModule and so forth.

Since this seems to run before the DOM is even loaded, I needs to find a way to ensure that nls/synapse_en-gb.js is not run until the DOM is loaded.

Looking at my generated synapse/synapse.js, there is a *now function at the base that appears to preload the i18n files file. i.e.

"*now":function(r){
    r(["dojo/i18n!*preload*synapse/nls/synapse*[\"ar\",\"ca\",\"cs\",\"da\",\"de\",\"el\",\"en-gb\",\"en-us\",\"es-es\",\"fi-fi\",\"fr-fr\",\"he-il\",\"hu\",\"it-it\",\"ja-jp\",\"ko-kr\",\"nl-nl\",\"nb\",\"pl\",\"pt-br\",\"pt-pt\",\"ru\",\"sk\",\"sl\",\"sv\",\"th\",\"tr\",\"zh-tw\",\"zh-cn\",\"ROOT\"]"]);
}

I may end up having to relocate all the dojo loading until after so there's a much better chance of the DOM having been loaded, before dojo doing it's thing.

解决方案

I ended up having to move the inline portion of the script to after the </body> tag.

这篇关于如何防止“无法获取属性的值”dir':object is null或undefined“在IE9中加载页面时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆