IE下產生KB927917的javascript錯誤的解決方法.

最近在寫程式中遇到這樣一個錯誤

 

代码
網頁錯誤詳細資料

使用者代理程式: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0; .NET CLR 1.1.4322; .NET CLR 3.0.04506.648; .NET CLR 3.5.21022; .NET CLR 2.0.50727; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729)
時間戳記: Tue, 30 Mar 2010 01:42:50 UTC


訊息: 
HTML Parsing Error: Unable to modify the parent container element before the child element is closed (KB927917)
行: 0
字元: 0
程式碼: 0
URI: http://localhost:2322/ScheduleModel/Pages/SignMemberMaintain.aspx?CertificateKey=i9BmNO8EiDtUNbfbzY0W9sWk9QiNfmfrPG3hDrhtxIfenjYvmmTkkQ%3d%3d&

 

 

產生這個錯誤的代碼如下:

 

代码
                var msgw,msgh,bordercolor;     
                msgw
= 400 ;
                msgh
= 100 ;     
                titleheight
= 25         
                bordercolor
= "" # 336699 "" ;
                titlecolor
= "" #99CCFF "" ;     

                var bgObj 
=  document.createElement( "" div "" );   
                bgObj.setAttribute(
"" id "" "" bgDiv "" );
                bgObj.style.position 
=   "" absolute "" ;
                bgObj.style.top 
=  document.getElementById( ' " + UpdatePanel1.ClientID + @" ' ).offsetTop  +   "" px ""
                bgObj.style.background 
=   "" # 777 "" ;
                bgObj.style.filter 
=   "" progid:DXImageTransform.Microsoft.Alpha(style = 3 ,opacity = 25 ,finishOpacity = 75 "" ;
                bgObj.style.opacity 
=   "" 0.6 "" ;
                bgObj.style.left 
=  document.getElementById( ' " + UpdatePanel1.ClientID + @" ' ).offsetLeft  +   "" px ""
                bgObj.style.width 
=  document.getElementById( ' " + UpdatePanel1.ClientID + @" ' ).offsetWidth  +   "" px ""
                bgObj.style.height 
=  document.getElementById( ' " + UpdatePanel1.ClientID + @" ' ).offsetHeight  +   "" px ""
                bgObj.style.zIndex 
=   "" 10000 "" ;
                document.getElementById(
' " + UpdatePanel1.ClientID + @" ' ).appendChild(bgObj);

                var msgObj
= document.createElement( "" div "" );
                msgObj.setAttribute(
"" id "" , "" msgDiv "" );     
                msgObj.setAttribute(
"" align "" , "" center "" );     
                msgObj.style.background
= "" white "" ;     
                msgObj.style.border
= "" 1px   solid    ""     +    bordercolor;     
                msgObj.style.position   
=     "" absolute "" ;     
                msgObj.style.left   
=     "" 50 % "" ;     
                msgObj.style.top   
=     "" 50 % "" ;     
                msgObj.style.font
= "" 12px / 1 .6em   Verdana,   Geneva,   Arial,   Helvetica,   sans - serif "" ;     
                msgObj.style.marginLeft   
=     "" - 225px ""    ;     
                msgObj.style.marginTop   
=     - 75 + document.documentElement.scrollTop + "" px "" ;     
                msgObj.style.width   
=    msgw    +     "" px "" ;     
                msgObj.style.height   
= msgh    +     "" px "" ;     
                msgObj.style.textAlign   
=     "" center "" ;     
                msgObj.style.lineHeight   
= "" 25px "" ;     
                msgObj.style.zIndex   
=     "" 10001 "" ;     
                
document.body.appendChild(msgObj);

                var txt
= document.createElement( "" p "" );  
                txt.style.margin
= "" 1em    0 ""      
                txt.setAttribute(
"" id "" , "" msgTxt "" );     
                txt.innerHTML
= "" 頁面初始化資料不全,請勿操作 ! "" ;     
                document.getElementById(
"" msgDiv "" ).appendChild(txt);  

 

 

產生錯誤的那句我已經Highlight.初步認為是在Body還沒有處理結束的時候又向裡面加入新的元素導致(It is not fully loaded).

此時document正處於loading與interactive狀態之間

 

解決方法:

 

1.先進行document.readyState狀態判斷,當它為complete時再進行相應的操作,或者給script標籤加上defer屬性(該屬性在IE8中已不獲支持)。

jquery裏的$(document).ready(function(){
// 在這裏寫你的代碼...
});

 

或者

 

2.javascript中加入了 setTimeout("XXXX()",1000);,使其獲得足夠的載入時間後執行目標(XXXX)的function

 

 

你可能感兴趣的:(JavaScript)