键盘快捷键,打开新窗口 [Chrome 扩展]
我正在尝试开发一个 Chrome 扩展程序,您可以按键盘快捷键,URL 将在新窗口中加载,但我只能在同一选项卡中打开 URL。
script.js
if (window == top) {
window.addEventListener('keyup', doKeyPress, false); //add the keyboard handler
}
var post = "urlhere.com";
var trigger_key = 85; // u key
function doKeyPress(e){
if (e.altKey && e.keyCode == trigger_key) {
chrome.extension.sendRequest({redirect: post});
}
}
background.html
<script>
chrome.browserAction.onClicked.addListener(function() {
var w = 440;
var h = 220;
var left = (screen.width/2)-(w/2);
var top = (screen.height/2)-(h/2);
chrome.windows.create({'url': 'redirect.html', 'type': 'popup', 'width': w, 'height': h, 'left': left, 'top': top} , function(window) {
});
});
chrome.extension.onRequest.addListener(function(request, sender) {
chrome.tabs.update(sender.tab.id, {url: request.redirect});
});
</script>
到目前为止,上述所有内容都有效,具体的网址将显示,但在同一个选项卡中。它是否可以显示一个新的(弹出)窗口? 我已经尝试了大量的编码,但没有这样的运气。
我尝试过这个,但没有成功
(window == top) {
window.addEventListener('keyup', doKeyPress, false); //add the keyboard handler
}
var post = "urlhere.com";
var w = 440;
var h = 220;
var left = (screen.width/2)-(w/2);
var top = (screen.height/2)-(h/2);
var trigger_key = 85; // u key
function doKeyPress(e){
if (e.altKey && e.keyCode == trigger_key) {
chrome.browserAction.onClicked.addListener(function() {
chrome.windows.create({'url': 'redirect.html', 'type': 'popup', 'width': w, 'height': h, 'left': left, 'top': top} , function(window) {
});
});
}
}
I'm trying to develop a Chrome extension where you press a keyboard shortcut and the URL will load in a new window, but I can only get the URL to open in the same tab.
script.js
if (window == top) {
window.addEventListener('keyup', doKeyPress, false); //add the keyboard handler
}
var post = "urlhere.com";
var trigger_key = 85; // u key
function doKeyPress(e){
if (e.altKey && e.keyCode == trigger_key) {
chrome.extension.sendRequest({redirect: post});
}
}
background.html
<script>
chrome.browserAction.onClicked.addListener(function() {
var w = 440;
var h = 220;
var left = (screen.width/2)-(w/2);
var top = (screen.height/2)-(h/2);
chrome.windows.create({'url': 'redirect.html', 'type': 'popup', 'width': w, 'height': h, 'left': left, 'top': top} , function(window) {
});
});
chrome.extension.onRequest.addListener(function(request, sender) {
chrome.tabs.update(sender.tab.id, {url: request.redirect});
});
</script>
So far, all of the above works, the specific url will display, but in the same tab. Is it possible for it to display a a new (popup) window?
I've tried numerous amounts of coding, but no such luck.
I tried this, but it did not work
(window == top) {
window.addEventListener('keyup', doKeyPress, false); //add the keyboard handler
}
var post = "urlhere.com";
var w = 440;
var h = 220;
var left = (screen.width/2)-(w/2);
var top = (screen.height/2)-(h/2);
var trigger_key = 85; // u key
function doKeyPress(e){
if (e.altKey && e.keyCode == trigger_key) {
chrome.browserAction.onClicked.addListener(function() {
chrome.windows.create({'url': 'redirect.html', 'type': 'popup', 'width': w, 'height': h, 'left': left, 'top': top} , function(window) {
});
});
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我使用此功能在新窗口中打开:
I use this function for opening in a new window: