我可以使用 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/