Chrome扩展程序在当前窗口后面打开新窗口 [英] Chrome extension open new window behind the current window
问题描述
我有一个使用
window.open()自动打开窗口的扩展名。
当用户打开一些特定的网站。
我想要的是通过window.open()从后台脚本打开的新窗口应显示在用户打开的当前webiste后面。
我已经尝试window.open属性像alwaysLowered = 1,z锁= 1等,但不工作。
也试过.....
var w = window.open('url');
if(w){
w.blur();
window.focus();
}
所有这些对chrome都没有影响。任何人都可以帮忙吗?
如果您不需要打开窗口的句柄(由 window.open
),您可以使用 chrome.windows
API 的方法 create
和
background.js ::
chrome.browserAction。 onClicked.addListener(function(tab){
chrome.windows.create({url:http://www.google.com/},function(win){
chrome.windows.update (win.id,{focused:false});
});
});
从理论上讲,通过 更新: i have a chrome extension which automatically open a window using
window.open();
when user open some specific websites.
what i want is the new window which i open from the background script through window.open() should be displayed behind the current webiste opened by the user. i have tried window.open properties like alwaysLowered=1, z-lock=1 etc. but not working.
Also tried..... all these have no effect on chrome. can anybody help? If you don't need the handle to the opened window (returned by In background.js: Theoretically, passing the UPDATE:
这篇关于Chrome扩展程序在当前窗口后面打开新窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!集中:false $ c $ createInfo 参数中的c>属性应该一次达到相同的结果,但在Windows上使用Chrome 31.0.1650.57版本时不适用于我。
上面的代码似乎没有模糊MAC上的窗口。为了克服这个问题(在确定新窗口的位置和大小时 - 根据OP的评论)使用以下代码:
chrome .browserAction.onClicked.addListener(function(tab){
chrome.windows.create({
url:http://www.google.com/,
width:430,
height:150,
top:top_popup,
left:left_popup
},function(win){
chrome.windows.update(tab.windowId,{focused :true});
});
});
var w = window.open('url');
if(w){
w.blur();
window.focus();
}
window.open
), you can use the chrome.windows
API's methods create
and update
:chrome.browserAction.onClicked.addListener(function(tab) {
chrome.windows.create({ url: "http://www.google.com/" }, function(win) {
chrome.windows.update(win.id, { focused: false });
});
});
focused: false
property in the createInfo argument should achieve the same result in one step, but it is not working for me with Chrome version 31.0.1650.57 on Windows.
The above code seems to not "blur" the window on MACs. To overcome this (while determining the position and size of the new window - as per OP's comment) use the following code:chrome.browserAction.onClicked.addListener(function(tab) {
chrome.windows.create({
url: "http://www.google.com/",
width: 430,
height: 150,
top: top_popup,
left: left_popup
}, function(win) {
chrome.windows.update(tab.windowId, { focused: true });
});
});