gpt4 book ai didi

javascript - 在 Google Chrome 扩展程序上打开一个新标签

转载 作者:数据小太阳 更新时间:2023-10-29 05:08:40 24 4
gpt4 key购买 nike

这是我的 background.html 文件,在当前选项卡中打开时它工作正常,但我希望它在新选项卡中打开,我做错了什么?

<html>
<head>
<script>
// Called when the user clicks on the browser action.
chrome.browserAction.onClicked.addListener(function(tab) {
var action_url = "javascript:location.href='http://www.reddit.com/submit?url='+encodeURIComponent(location.href)+'&title='+encodeURIComponent(document.title)";
chrome.tabs.create(tab.id, {url: action_url}, function(tab));
});
</script>
</head>
</html>

最佳答案

您应该阅读chrome.tabs.create documentation再次。您正在向它传递无效参数。您还使用了 location,它来自 background.html 文档,而不是代码期望的网页文档,而不是传递给 tab 的参数chrome.browserAction.onClicked 监听器。

<html>
<head>
<script>
// Called when the user clicks on the browser action.
chrome.browserAction.onClicked.addListener(function(tab) {
var action_url = "http://www.reddit.com/submit?url=" + encodeURIComponent(tab.href) + '&title=' + encodeURIComponent(tab.title);
chrome.tabs.create({ url: action_url });
});
</script>
</head>
</html>

关于javascript - 在 Google Chrome 扩展程序上打开一个新标签,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8457382/

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