Home » javascript, 原创

IE中JS错误(KB927917)的解决办法

5 03月 2010 Views: One Comment Tags:

博客用了半静态化后,使用了月光的js版postviews,但是ie会提示KB927917的错误,计数器有时候也不会正常工作。查了一些资料,终于解决了。

页面错误提示:Unable to modify the parent container element before the child element is closed (KB927917)

错误描述:“用户代理: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; Trident/4.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media CenterPC 6.0; InfoPath.2),时间戳: Tue, 12 May 2009 13:49:16 UTC消息: HTML Parsing Error: Unable to modify the parent container element before the child element is closed (KB927917)行: 0字符: 0代码: 0。”

简单描述:子HTML元素内包含试图修改子容器的父容器元素的脚本。

去微软知识库查了KB927917,其说明写道:“出现此问题的原因子容器 HTML 元素包含试图修改子容器的父容器元素的脚本。 脚本试图使用innerHTML  方法或  appendChild  方法修改父容器元素。例如如果 DIV 元素是在 BODY 元素中的子容器,并在 DIV 元素中的一个 SCRIPT 块尝试修改 DIV 元素的父容器的BODY 元素,可能会出现此问题”。
这个问题是伟大的浏览器IE发现的,各大浏览器没有这种反馈,原因就是解析的JavaScript的机制不同。这个问题一直到IE8还是存在,估计一直也存在。因为解析JavaScript的解析IE是边读边执行的,所以如果脚本允许修改父元素,并且子元素又没关闭的话,会失去条理性。

 

解决:将JS代码或引用文件放入页面底部的body之后,这样代码在body被解释之后执行,就不会出现这个错误了,对于js版的postviews,将footer.php中的

<?php wp_footer(); ?>

放置于</body>后即可。如果有其他内容需要置于body内的。则修改插件postviews.php文件81行左右,将如下语句注释掉

#add_action("wp_footer","the_views_javascript");

然后将下面的代码置入footer.php的后面

<?php
if(is_single() ){
	echo "<script language=\"javascript\" type=\"text/javascript\">
try{
	var elScript = document.createElement(\"script\");
	elScript.setAttribute(\"language\", \"javascript\");
	elScript.setAttribute(\"src\", \"".get_option("home")."/wp-counter.php?post_id=\" + escape(strBatchView));
	document.getElementsByTagName(\"body\")[0].appendChild(elScript);
	}
catch(e){};
</script> ";
	}
?>

原创文章如转载,请注明:转载自Xixis Blog [ http://www.xixis.net/ ]
本文链接地址:http://www.xixis.net/archives/ie-in-the-js-error-kb927917-solution.html

One Comment »

  • moho said:

    ie9已经不存在了

Leave your response!

Add your comment below, or trackback from your own site. You can also subscribe to these comments via RSS.

Be nice. Keep it clean. Stay on topic. No spam.

You can use these tags:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="">

This is a Gravatar-enabled weblog. To get your own globally-recognized-avatar, please register at Gravatar.