为什么 chrome 会抛出“Uncaught Error: NOT_FOUND_ERR: DOM Exception 8”这里?
下面是我的 YWA 包装器的代码,
var astr_ywascript = (document.createElement("script").type = "text/javascript").src = "http://d.yimg.com/mi/eu/ywa.js";
document.head.appendChild(astr_ywascript); // <- error on this line
它在页面加载时运行,因此 JS 找不到文档头标记是没有意义的。
有什么想法吗?
谢谢
Opera 在同一行抛出此错误。 未捕获的异常:错误:WRONG_ARGUMENTS_ER
Firebug 说:document.head 未定义 [中断此错误] document.head.appendChild(astr_ywascript);
Below is the code for my YWA wrapper
var astr_ywascript = (document.createElement("script").type = "text/javascript").src = "http://d.yimg.com/mi/eu/ywa.js";
document.head.appendChild(astr_ywascript); // <- error on this line
It's run on page load, so it makes no sense that JS can't find the document head tag.
Any ideas?
Thanks
Opera throws this error on the same line. Uncaught exception: Error: WRONG_ARGUMENTS_ER
Firebug says: document.head is undefined [Break On This Error] document.head.appendChild(astr_ywascript);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
在该行中,
您将设置字符串的 src 属性。括号中的赋值返回指定的值。您在该行后面犯了同样的错误,最终将
"http://d.yimg.com/mi/eu/ywa.js"
分配给astr_ywascript
将其拆分出来分成单独的行:
原始 Javascript 很少以人们习惯的 jQuery 流畅方式运行。
您可能还想按如下方式获取头部:
In the line
you are setting the src property of a string. The assignment in parentheses returns the assigned value. You make the same mistake later in the line, ultimately assigning
"http://d.yimg.com/mi/eu/ywa.js"
toastr_ywascript
Split it out onto separate lines:
Raw Javascript rarely behaves in the fluid way one gets used to with jQuery.
You might also want to get the head as follows:
我在 Backbone.js 中遇到了这个错误,因为我正在做:
而不是像
我应该做的那样。我仍然不太清楚这个“el”业务是什么,但我相信我很快就会弄清楚。
I got this error with Backbone.js because I was doing:
Instead of
Like I should have done. Still don't really know what this 'el' business is, but I'm sure I'll figure it out soon.
只是为那些可能会像我一样在搜索
“Uncaught Error: NOT_FOUND_ERR: DOM Exception 8
错误的答案时点击此页面的人附加此答案。我在 Chrome 中遇到了这个错误。就我而言,我使用的是
.appendChild(ttt);
问题是
ttt
是一个数组对象,而不是我打算附加的 div。因此,请确保您要附加的实际上是 DOM 对象,而不是意外的不同对象类型。
Just appending this answer for people who might hit this page like I did while searching for an answer to a
“Uncaught Error: NOT_FOUND_ERR: DOM Exception 8
error.I had this error in Chrome. In my case I was using
.appendChild(ttt);
The issue was that
ttt
was an array object instead of the div I intended to append.So make sure what you are appending is actually a DOM object and not accidentally a different object type.