谷歌浏览器扩展:如何不止一次打开一个新的浏览器窗口? [英] google chrome extension : how to open a new browser window more than once?
问题描述
我的Chrome扩展程序通过这个简单的JS打开一个新的浏览器窗口:
chrome.browserAction.onClicked.addListener(function( tab){
var room = new Date()。getTime();
win = window.open(http://www.example.com/page.html#+ room,win ,width = 485,height = 55);
});
这很好,但只有一次。
<第二次点击,它只是把焦点放在窗口上,但URL根本不会改变。
我也试过这个(没有成功):
win .location =http://www.example.com/page.html#\"+room;
win.location.reload();
window.open() 是一个通用的JavaScript函数; Chrome的使用率限制了它,因此恶意网页无法产生许多窗口。
window.open
。由于您重复使用同一个,因此不会打开新窗口。然而,作为扩展,您可以访问不受限制的工具。 也就是说,看看
chrome.windows
和 chrome.tabs
APIs。 chrome.windows.create({url:fullyQualifiedURLHere});
请注意 create
/ update
方法不需要特殊权限。
My Chrome extension opens a new browser window with this simple JS:
chrome.browserAction.onClicked.addListener(function(tab) {
var room = new Date().getTime();
win = window.open("http://www.example.com/page.html#"+room,"win","width=485,height=55");
});
This works great, but just once.
Second time I click, it just put the focus on the window but URL does not change at all.
I also tried this (with no success):
win.location = "http://www.example.com/page.html#"+room;
win.location.reload();
window.open()
is a generic JavaScript function; Chrome rate-limits it so that malicious pages can't spawn many windows.
There is a concept of a "window name" with window.open
. Since you're reusing the same one, it's not opening a new window. And the above rate-limiting still can apply.
However, as an extension, you have access to unrestricted tools.
Namely, take a look at chrome.windows
and chrome.tabs
APIs.
chrome.windows.create({url: "fullyQualifiedURLHere"});
Note that create
/update
methods do not require special permissions.
这篇关于谷歌浏览器扩展:如何不止一次打开一个新的浏览器窗口?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!