简体   繁体   English

关闭按钮在 Chrome 扩展弹出窗口中打开新的 chrome 商店标签

[英]Close button opens new chrome store tab on Chrome extension popup

We have a Chrome extension download button on our site.我们的网站上有一个 Chrome 扩展下载按钮。

When you click it, it opens a popup that says 'Add extension', 'Cancel' etc.当你点击它时,它会打开一个弹出窗口,上面写着“添加扩展”、“取消”等。

http://i.imgur.com/RFuts0E.png http://i.imgur.com/RFuts0E.png 我指的是弹出窗口

The image shows the popup I'm referring to.该图像显示了我所指的弹出窗口。

It works fine, except for the cancel button opens a new tab and takes you to the plugins chrome store page.它工作正常,除了取消按钮会打开一个新选项卡并带您进入插件 chrome 商店页面。

I have no idea why it does this, or how to just get it to cancel.我不知道它为什么这样做,或者如何让它取消。

The js: js:

chrome.webstore.install(webStoreURL, () => null, (error, errorCode) => {
   window.open(PLUGIN_LINKS.Chrome, '_blank');
});

Any help is much appreciated.任何帮助深表感谢。

Well, you indiscriminately try to open the Webstore page on "error".好吧,您不加选择地尝试在“错误”上打开 Webstore 页面。 In fact, user clicking Cancel is one ofmany "error" conditions .事实上,用户点击取消是许多“错误”条件之一

You need to analyze the errorCode to filter that out.您需要分析errorCode以将其过滤掉。

chrome.webstore.install(webStoreURL, () => null, (error, errorCode) => {
   if (errorCode !== "userCanceled") {
       window.open(PLUGIN_LINKS.Chrome, '_blank');
   }
});

Note: as is obvious from the error code list, there are many other conditions that make opening the Web Store page useless.注意:从错误代码列表中可以明显看出,还有许多其他条件导致无法打开 Web Store 页面。 You should re-think this logic.你应该重新考虑这个逻辑。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM