如何在Chrome扩展程序中隐藏popup.html

时间:2020-04-08 04:57:21

标签: google-chrome-extension

这是我的设置,我正在尝试确定是否可能。 我有一个Chrome扩展程序,可以解析活动页面中的一些数据,然后将结果复制到剪贴板。我的popup.html很小,看起来像这样

<!DOCTYPE html>
<html style=''>
<head>
<script src='popup.js'></script>
</head>
<body style="width:600px;">
<textarea id="emailphone" cols="50" rows="10"></textarea>
<br>
<button id="copy-to-clipboard">Copy to Clipboard</button>
</body>
</html>

我想做的实际上是在我的脚本运行并创建警报并显示数据时甚至根本不显示弹出窗口。但是有一个我的脚本用解析的数据设置了电子邮件电话文本区域的内部HTML,然后我将文本区域复制到剪贴板。这是我的弹出脚本

chrome.runtime.onMessage.addListener(function(request, sender) {
    if (request.action == "getSource") {
      emailphone.innerText = request.source;
      myFunction();

    }
  });
  document.addEventListener('DOMContentLoaded', function() {
    document.getElementById("copy-to-clipboard").addEventListener("click", copytoclipboard);
  });

  function onWindowLoad() {

    var message = document.querySelector('#emailphone');

    chrome.tabs.executeScript(null, {
      file: "getPagesSource.js"
    }, function() {
      // If you try and inject into an extensions page or the webstore/NTP you'll get an error
      if (chrome.runtime.lastError) {
        emailphone.innerText = 'There was an error injecting script : \n' + chrome.runtime.lastError.message;
      }
    });

  }
  function copytoclipboard() {
    var copyText = document.getElementById("emailphone");
    copyText.select();
    copyText.setSelectionRange(0, 99999)
    document.execCommand("copy");
    alert(copyText.value);
  }

  window.onload = onWindowLoad;

当我使用window.close()时,它仅在关闭警报后关闭。所以我要寻找的只是显示警报,而不显示popup.html

0 个答案:

没有答案