これにより、popup.html で無制限の数のタブが開きます。1 つのタブのみが開かれるように変更するにはどうすればよいですか。
chrome.tabs.create({'url': chrome.extension.getURL('popup.html')}, function(tab) {
// Tab opened.
});
編集: (基本的な popup.html)
<!DOCTYPE html>
<html lang="en">
<!--<script src="script.js"></script>-->
<script src="jquery.min.js"></script>
<script src="popup.js"></script>
<head>
<meta charset="utf-8">
<title> Chrome Extension</title>
<!--<link rel="stylesheet" href="style.css" />-->
</head>
<body id="container">
<div id="left">
<div class="input-wrapper">
hello
</div>
</div> <!-- end #left -->
</body>
</html>
popup.js
function openTab()
{
filename = "popup.html"
var myid = chrome.i18n.getMessage("@@extension_id");
chrome.windows.getCurrent(
function(win)
{
chrome.tabs.query({'windowId': win.id},
function(tabArray)
{
for(var i in tabArray)
{
if(tabArray[i].url == "chrome-extension://" + myid + "/" + filename)
{
// console.log("already opened");
chrome.tabs.update(tabArray[i].id, {active: true});
return;
}
}
chrome.tabs.create({url:chrome.extension.getURL(filename)});
});
});
}
openTab();
マニフェスト.json:
{
"name": "App",
"version": "1.1",
"manifest_version": 2,
"description": "Test",
"background_page": "background.html",
"browser_action": {
"name": "App",
"icons": ["icon.png"],
"default_icon": "icon.png",
"default_popup":"popup.html"
},
"content_scripts": [ {
"js": [ "jquery.min.js", "background.js" ],
"matches": [ "http://*/*", "https://*/*"]
}],
"permissions": [ "<all_urls>",
"storage",
"tabs",
"contextMenus" ]
}