【问题标题】:Open Chrome extension from link on website从网站上的链接打开 Chrome 扩展程序
【发布时间】:2013-11-21 19:54:03
【问题描述】:

我想通过我网站上的链接打开一个 Chrome 扩展程序(作为背景页面)。

我尝试过的事情:

  • 创建一个a 标记链接到扩展程序的主 HTML 页面。
  • 将用户发送到执行 302 重定向到 HTML 页面的页面。
  • 使用Javascript重定向用户,window.location = ...

所有这些都不起作用,而是打开一个about:blank 页面。例外(这似乎很奇怪)是当我使用策略 #2 并且从我的桌面邮件客户端打开链接时。

关于如何实现这一点的任何想法?在我们的例子中,请求tabs 权限是不可能的。

【问题讨论】:

  • 您的操作系统/Chrome 版本是什么?

标签: javascript html google-chrome-extension


【解决方案1】:

尝试阅读您的扩展程序的message passing from a webpage to a background page(听起来像是您想要完成的事情)。

【讨论】:

    【解决方案2】:

    您需要在清单的 web_accessible_resources 部分添加 taregt HTML 文件。例如:

    扩展文件结构:

              root-dir/
               |_____manifest.json
               |_____content.js
               |_____myfile.html
    

    content.js:

    /* Append a link to the web-page's body */
    var a = document.createElement("a");
    a.href = chrome.extension.getURL("myfile.html");
    a.target = "_blank";
    a.textContent = "My HTML file";
    document.body.appendChild(a);
    

    ma​​nifest.json:

    {
        "manifest_version": 2,
        "name":    "Test Extension",
        "version": "0.0",
        "offline_enabled": true,
    
        "content_scripts": [{
            "matches":    ["*://*/*"],
            "js":         ["content.js"],
            "run_at":     "document_end",
            "all_frames": false
        }],
    
        "web_accessible_resources": ["myfile.html"]
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-03-14
      • 2017-12-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-11-09
      相关资源
      最近更新 更多