javascript - 如何在没有新标签的情况下打开 popup.html?

标签 javascript google-chrome google-chrome-extension

我有一个扩展示例,弹出窗口作为新选项卡打开。

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

enter image description here

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

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>

最佳答案

已解决:

manifest.json 中:

"browser_action": {

"default_popup": "w3c.html"

},

关于javascript - 如何在没有新标签的情况下打开 popup.html?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37232705/

相关文章:

google-chrome - 在 Chrome 上伪造 USB 设备

javascript - 监听元素的创建并在它出现在 Chrome 扩展程序的页面上时触发事件

javascript - 在 Chrome 扩展中使用 sendMessage 时 webkitMediaStream 对象类型丢失

javascript - 使用 typeof 进行输入验证

javascript - html 中预加载的数据

google-chrome - 如何检测浏览器是否支持 contenteditable 参数中的 "plaintext-only"值?

html - 在 HTML 中检测 Chrome 浏览器

javascript - leaflet.js 显示空 map : Uncaught Error: Invalid LatLng object: (NaN, NaN)

javascript - 如何在 select_node 事件上为 jstree 添加元数据

google-chrome - 点击时显示页面操作弹出窗口