执行时候出现以下:
Microsoft JScript 运行时错误: 重新声明常量“document”
小妹初学,不知道以上是哪里出错了,请各位大神帮忙一下,谢谢,拜托
看不懂哦,你是声明变量和document同名了? 我果断猜的。。。
你的document是怎么调用的?有地方用着这个变量了(同名)?
<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-16716654-1']);
_gaq.push(['_trackPageview']);
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? ' https://ssl' : ' http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
</script>
出问题的那段js代码是怎么写的?
<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-16716654-1']);
_gaq.push(['_trackPageview']);
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? ' https://ssl' : ' http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
</script>
@Vivianwwa: IE用的是哪个版本?
@dudu: IE9
@Vivianwwa:
问题可能是IE9使用了quirks mode(怪异模式)引起的
建议加上DOCTYPE声明,比如:
<!DOCTYPE html>
参考资料:
JS error 'redeclaration' of var when it's first line in program?
请贴点代码,我猜也是申明了一个document的变量,然后...error~
<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-16716654-1']);
_gaq.push(['_trackPageview']);
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? ' https://ssl' : ' http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
</script>
@Vivianwwa: 在Chrome上测试,无错。参考下楼上的解决方案吧~
路过学习