【发布时间】:2013-03-09 05:05:45
【问题描述】:
我的网页html代码中有这个js函数。
function update() {
document.getElementById( "textbox ").value = updatetext;
}
当我从 chrome 控制台执行“update()”时,它可以工作。
但是如果我从 chrome 扩展执行,
chrome.tabs.executeScript(tab.id, {code: "update();"}, function(result){});
它说没有定义更新。但如果我用“alert('ok')”替换,它就可以了。
然后我执行
eval("update()")
在 Chrome 扩展内容脚本中。它还说“未定义更新。”
那么我该怎么做才能在网页上调用js函数呢?
【问题讨论】:
-
对于您在 cmets 中的问题,甚至更好:Executing code at page-level from Background.js and returning the value
标签: javascript google-chrome google-chrome-extension