2011-05-29 48 views
5

我用新的IE 9測試了我的網站,發現錯誤告訴我INVALID_CHARACTER_ERR(5)。在IE 9中,開發人員工具突出顯示了這一行。誰能幫我這個錯誤?Javascript:DOM例外:INVALID_CHARACTER_ERR(5)

錯誤行

this.iframe = document.createElement('<IFRAME src="' + myCurrentUrl + '" frameborder=0>'); 


Function Code 
__createDivs : function() 
{ 
this.divs_transparentDiv = document.createElement('DIV'); 
this.divs_transparentDiv.className='modalDialog_transparentDivs'; 
this.divs_transparentDiv.style.left = '0px'; 
this.divs_transparentDiv.style.top = '0px'; 
document.body.appendChild(this.divs_transparentDiv); 
this.divs_content = document.createElement('DIV'); 
this.divs_content.className = 'modalDialog_contentDiv'; 
this.divs_content.id = 'DHTMLSuite_modalBox_contentDiv'; 
this.divs_content.style.zIndex = 100000; 
if(this.MSIE){ 
var myCurrentUrl = GlobPanelCurrentBaseUrl + 'images/spacer.gif'; 
this.iframe = document.createElement('<IFRAME src="' + myCurrentUrl + '" frameborder=0>'); 
this.iframe.style.zIndex = 90000; 
this.iframe.style.position = 'absolute'; 
document.body.appendChild(this.iframe); 
} 
document.body.appendChild(this.divs_content); 
this.divs_shadow = document.createElement('DIV'); 
this.divs_shadow.className = 'modalDialog_contentDiv_shadow'; 
this.divs_shadow.style.zIndex = 95000; 
document.body.appendChild(this.divs_shadow); 
window.refToModMessage = this; 
this.addEvent(window,'scroll',function(e){ window.refToModMessage.__repositionTransparentDiv() }); 
this.addEvent(window,'resize',function(e){ window.refToModMessage.__repositionTransparentDiv() }); 
} 
像這樣就可以了
+2

僅供參考,允許舊版本的IE您將任意HTML傳遞到createElement,但這違反了規範。 – Neil 2011-05-29 20:05:01

回答

10

是的,你應該只給它的元素的名稱,然後設置屬性:

this.iframe = document.createElement('iframe'); 
this.iframe.src = myCurrentUrl; 
this.iframe.frameBorder = 0; 
+0

謝謝,我只是能夠解決它使用以下 this.iframe = document.createElement(「iframe」); this.iframe.setAttribute(「src」,myCurrentUrl); this.iframe.setAttribute(「style」,「position:absolute; z-index:90000;」); this.iframe.frameBorder = 0; – 2011-05-29 19:45:44