如何从网页获取谷歌扩展的价值

问题描述 投票:0回答:1

我需要不断地将这个值输入到我的谷歌扩展程序弹出窗口,或者从一个将成为当前标签页的网页下一个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;

    });
}

仍然没有获得价值或弹出任何警报

javascript html dom
1个回答
0
投票

var serverTime = document.getElementById('serverTime')只获得元素。你想获得价值

var serverTime = document.getElementById('serverTime').value
© www.soinside.com 2019 - 2024. All rights reserved.