javascript - Chrome 内联插件安装在 window.confirm 上

标签 javascript google-chrome google-chrome-extension google-chrome-app chrome-web-store

我可以使用 window.confirm触发 Chrome 扩展/应用 inline installation

To actually begin inline installation, the chrome.webstore.install(url, successCallback, failureCallback) function must be called. This function can only be called in response to a user gesture, for example within a click event handler; an exception will be thrown if it is not.

来自文档:必须调用 chrome.webstore.install 来响应用户手势。我可以使用浏览器确认弹出窗口来完成此操作吗?

 if (confirm("Press a button!") == true) {
   var app =
     'https://chrome.google.com/webstore/detail/omcplobmjajgpmpcdnbdiblienjeljan';
   chrome.webstore.install(app, function() {
     console.log('Success');
   }, function(errorMessage) {
     console.log('Error: ' + errorMessage)
   });
 }
<link 
  rel="chrome-webstore-item" 
  href="https://chrome.google.com/webstore/detail/omcplobmjajgpmpcdnbdiblienjeljan"
>

我无法自己测试,因为我没有经过验证的域

最佳答案

什么首先触发确认?我猜这是重要的部分。如果您事先没有用户交互就弹出确认,我怀疑它是否会起作用。

据我了解用户手势要求,这意味着“在用户手势触发的事件监听器的上下文中”。来自模式的响应不是这样的监听器。 注意:这是一个猜测,我还没有测试过。

Since inline installation has to be triggered via a user gesture (for example, a mouse click) it is therefore suggested that you tie the action to a clickable user interface element such as a button. It is suggested that you use the same button label as the Chrome Web Store itself (in English, this is "Add to Chrome").

此处的文档指的是 DOM 元素,即使它并不明确。

事实上,如果它在显示对话框之前无需用户手势即可工作,我会认为这是一个错误,因为用户无法避免与确认进行交互。

关于javascript - Chrome 内联插件安装在 window.confirm 上,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39744345/

相关文章:

javascript - 当我的单元测试失败时回调被调用两次

javascript - 使用 javascriptHey 获取内容框的大小

javascript - Mp3 ID3标签,令人困惑的APIC框架结构

css - 如何在不同浏览器中对一个类应用不同的css样式

javascript - Mac OS X 上的 Chrome 扩展 : Window popups disappear

javascript - Chrome 扩展程序。为弹出菜单中的按钮分配功能

javascript - 使用小部件工厂扩展时,JQuery UI Droppable 贪婪选项不起作用

python - 如何在 Selenium 中正确启动 Chrome

jQuery UI 在 Firefox 中工作,但在 Chrome 和 Safari 中不工作?

css - 我的 CSS 没有通过我的内容脚本注入(inject)