gpt4 book ai didi

google-chrome-extension - 弹出窗口,中心屏幕

转载 作者:行者123 更新时间:2023-12-04 03:13:22 25 4
gpt4 key购买 nike

我正在使用以下代码在 Google Chrome 扩展程序中打开一个弹出窗口,我的一个问题是,如何让弹出窗口在用户屏幕的中心打开?

 <script>
chrome.browserAction.onClicked.addListener(function() {
var left = (screen.width/2)-(w/2);
var top = (screen.height/2)-(h/2);
chrome.windows.create({'url': 'redirect.html', 'type': 'popup', 'width': 440, 'height': 220, 'left': '+left+', 'top': '+top+', } , function(window) {
});
});
</script>

我也试过这个,结果没有这样的运气。
  <script>
chrome.browserAction.onClicked.addListener(function() {
chrome.windows.create({'url': 'redirect.html', 'type': 'popup', 'width': 440, 'height': 220, 'left': (screen.width/2)-(w/2), 'top': (screen.height/2)-(h/2), } , function(window) {
});
});
</script>

最佳答案

当你看到var obj = {property: value} JS中的结构是一个对象创建。在您的代码中,您试图将包含窗口属性的对象传递给 chrome.windows.create()功能。

正确的代码应该是:

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) {
});
});

关于google-chrome-extension - 弹出窗口,中心屏幕,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5345435/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com