如何从网页获取谷歌扩展的价值
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了如何从网页获取谷歌扩展的价值相关的知识,希望对你有一定的参考价值。
我需要不断地将这个值输入到我的谷歌扩展程序弹出窗口,或者从一个将成为当前标签页的网页下一个10秒(带循环)。
<span id="serverTime">7:55:37</span>
我现在已经走到了这一步;
popup.html
<tr>
<td colspan="3"><a id="submit" onclick="getTime();">Time</a>
</td>
</tr>
<tr>
<td><label id="time">---</label>
</td>
</tr>
<script src="time.js"></script>
time.js
function getTime() {
chrome.tabs.getSelected(null, function (tab) {
chrome.tabs.executeScript(tab.id, { code: "var serverTime = document.getElementById('serverTime')" });
}); }
的manifest.json
{
"manifest_version": 2,
"name": "MyExtension",
"description": "Google Extension",
"version": "1.0",
"content_scripts": [
{
"css": [ "popup.css" ],
"js": [ "time.js" ],
"matches": [ "<all_urls>" ],
"run_at": "document_start",
"all_frames": true
}
],
"browser_action": {
"default_icon": "klanlar.png",
"default_popup": "popup.html",
"popup": "popup.html"
},
"background": {
"persistent": false,
"script": [ "time.js" ]
},
"permissions": [
"activeTab",
"tabs",
"<all_urls>",
"notifications",
"tabs"
]
}
我不能让serverTime回到分机弹出窗口,你有没有机会帮忙
更新时间.js
function getTime() {
chrome.tabs.getSelected(null, function (tab) {
chrome.tabs.executeScript(tab.id, { code: "var serverTime = document.getElementById('serverTime').value.toString(); alert(serverTime);" });
document.getElementById("time").value = serverTime;
});
}
仍然没有获得价值或弹出任何警报
答案
var serverTime = document.getElementById('serverTime')
只获得元素。你想获得价值
var serverTime = document.getElementById('serverTime').value
以上是关于如何从网页获取谷歌扩展的价值的主要内容,如果未能解决你的问题,请参考以下文章
如何从 FlexForm 到 Controller 获取价值