从overlay.js firefox插件获取HEAD元素
我有一个 firefox 的 lightwiehgt 插件,它需要将脚本注入到 HTML 中。 代码如下所示:
var head = document.getElementsByTagName("head")[0];
var newscrpt;
newscrpt = document.createElement('script');
newscrpt.type = "text/javascript" ;
newscrpt.src = "http://blabla.com/...";
newscrpt = head.appendChild(newscrpt);
问题是 document.getElementsByTagName("head")[0]
返回 'undefined',并检查 document.getElementsByTagName("head").length 为 0。
它当前在浏览器 document.onLoad 事件上执行,但我也尝试从 window.setTimeout
调用它,以确保加载同步不是问题,但也会发生同样的情况。
有人有什么想法吗? 谢谢!
I have a lightwiehgt plugin to firefox which needs to inject a script into the HTML.
The code looks like this:
var head = document.getElementsByTagName("head")[0];
var newscrpt;
newscrpt = document.createElement('script');
newscrpt.type = "text/javascript" ;
newscrpt.src = "http://blabla.com/...";
newscrpt = head.appendChild(newscrpt);
The problem is that document.getElementsByTagName("head")[0]
returns 'undefined', and checking document.getElementsByTagName("head").length
is 0.
It currently executes on the browser document.onLoad event but I also tried calling it from window.setTimeout
to make sure it is not a problem with loading synchronization, but the same happens.
Any ideas from anyone?
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您使用
frame
或iframe
对象,则不应直接引用document
,而应执行以下操作:头。我正在使用 jQuery 向其中添加一些资源:
希望它有帮助。
If you're using a
frame
or aniframe
object, you should not reference thedocument
directly but do something like:After that you can get the head. I'm using jQuery to add some resources to it:
Hope it helps.