使用清单V3时,如何在buckding.js中创建文档元素?
以前,我一直在使用清单v2,就像以下代码一样,我试图跟踪事件并将请求发送到Google Analytics(分析),但我从未遇到过问题。
if (request.action == "quick_popup_clicked") {
(function () {
var ga = document.createElement("script");
ga.type = "text/javascript";
ga.async = true;
ga.src = "./js/ga.js";
var s = document.getElementsByTagName("script")[0];
s.parentNode.insertBefore(ga, s);
})(_gaq.push(["_trackEvent", "quick_popup", "clicked"]));
}
但是,在将清单V2升级为V3之后,我会遇到一个错误,说文档未定义
。 我该如何解决这个问题?
Previously I'd been using Manifest V2 and like the below code I was trying to track an event and send a request to Google Analytics and I never had a problem.
if (request.action == "quick_popup_clicked") {
(function () {
var ga = document.createElement("script");
ga.type = "text/javascript";
ga.async = true;
ga.src = "./js/ga.js";
var s = document.getElementsByTagName("script")[0];
s.parentNode.insertBefore(ga, s);
})(_gaq.push(["_trackEvent", "quick_popup", "clicked"]));
}
But after upgrading Manifest V2 to the V3 I'm getting an error that said document is not defined
.
How can I solve this issue?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论