在响应函数中附加文档
不知道为什么,但当我尝试在响应函数中将元素附加到文档时遇到意外的标识符错误。我发现对文档进行任何操作似乎都会出现此错误。这是一个示例代码:
chrome.extension.sendRequest({send:data},function(response) {
document.body.innerHTML='test'
})
在我看来它应该可以工作,但显然现在可以了。这段代码位于内容脚本中,并且在该函数之外处理文档似乎工作得很好,但在尝试此操作时我总是得到“意外的标识符”。不幸的是,我无法在函数之外执行此操作,因为响应决定是否将元素添加到主体中。
Not sure why, but I'm getting an unexpected identifier error when trying to append an element to the document in a response function. I've found that doing anything with the document seems to give me this error. Here's a sample code:
chrome.extension.sendRequest({send:data},function(response) {
document.body.innerHTML='test'
})
It looks to me like it should work, but evidently it does now. This piece of code is located in the contentscript, and messing with the document outside of this function seems to work just fine, but I always get "unexpected identifier" when trying this. Unfortunately I cannot do it outside of the function because the response determines whether or not an element is added to the body.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您共享的代码应该可以工作。尝试重新启动浏览器,看看是否可以解决问题。
The code you shared should work. Try restarting your browser to see if that fixes it.