【问题标题】:How open a popup.html without new tab?如何在没有新标签的情况下打开 popup.html?
【发布时间】:2016-05-14 22:54:23
【问题描述】:

我有一个扩展示例,弹出窗口作为新标签打开。

所以,现在我想在同一个 Chrome 活动标签中打开这个弹出窗口,如下所示:

我已经尝试了几种方法,但直到现在都没有成功。

PS:我使用的是 Google Chrome V.50

这是在新标签页中打开我的弹出窗口的代码:

manifest.json

{  
    "background": {
    "scripts": ["action.js"],
    "persistent": false
},

    "name": "W3C cheatsheet",
    "version": "0.1",
    "manifest_version": 2,
    "description": "Show the W3C cheatsheet on a popup",

    "icons": { "48": "favicon.png" },

    "browser_action": {

            "default_icon": "favicon.png"

    },
    "permissions": ["http://*/", "tabs"]
}

action.js

chrome.browserAction.onClicked.addListener(function(tab) {
    chrome.tabs.create({'url': chrome.extension.getURL('w3c.html'), 'selected': true});
});

popup.html(本例中为w3c.html

<html>
<head>
<script>
</script>
<style>* {margin: 0; padding: 0; border: 0;}</style>
</head>
<body>
<iframe src="https://www.w3.org/2009/cheatsheet/" width="450" height="500"></iframe>
</body>
</html>

【问题讨论】:

  • 您能解释一下“在同一个 Chrome 活动选项卡中打开此弹出窗口”的意思吗?是否要替换活动选项卡的现有内容?
  • @JackA.,我已经编辑了我的问题。

标签: javascript google-chrome google-chrome-extension


【解决方案1】:

已解决:

manifest.json中:

"browser_action": {

"default_popup": "w3c.html"

},

【讨论】:

    【解决方案2】:

    W3 Schools 说要打开一个新窗口,你必须使用window.open("url here");

    试试这个代码:

    window.open({'url': chrome.extension.getURL('w3c.html'), 'selected': true});

    【讨论】:

      猜你喜欢
      • 2011-01-18
      • 1970-01-01
      • 1970-01-01
      • 2018-07-29
      • 1970-01-01
      • 1970-01-01
      • 2020-09-29
      • 1970-01-01
      • 2017-07-18
      相关资源
      最近更新 更多