gpt4 book ai didi

javascript - Chrome 扩展保持弹出窗口加载

转载 作者:行者123 更新时间:2023-11-28 03:25:24 24 4
gpt4 key购买 nike

我正在为某个互联网广播电台开发扩展程序。目前正在打开播放音乐的新窗口,但我想做一个扩展。

我创建了弹出窗口并将互联网广播电台的 URL 作为 iframe 放入其中。问题是,当弹出窗口关闭时,iframe 也会关闭,音乐也会停止,这有点令人难过。

关于如何在“关闭”时保持弹出窗口内容加载的任何想法?

最佳答案

设置 list 有

"background": {
"scripts": ["background.js"]
},

一旦执行脚本将运行的页面弹出窗口,您就可以通过这种方式加载脚本。

如果你这样做,我会建议添加关键命令来停止、暂停和播放命令,就像你的 list 一样。

 "commands": {
"commands": {
"Play": {
"suggested_key": {
"default": "Ctrl+Shift+U",
"mac": "Command+Shift+U"
},
"description": "Toggle feature foo"
},
"Stop": {
"suggested_key": {
"default": "Ctrl+Shift+Z",
"mac": "Command+Shift+D"
},
"description": "Toggle feature foo"
}
}

然后在您在 list 中设置的背景文件中添加一个 chrome 监听器

 chrome.commands.onCommand.addListener(function(command) {
console.log('Command:', command);
if(command == "Play"){
//play function here
}else if(command == "Stop"){
//stop function here
}
});

关于javascript - Chrome 扩展保持弹出窗口加载,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21540599/

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