【问题标题】:Launch a custom protocol handler using javascript in Chrome without a popup?在没有弹出窗口的情况下在 Chrome 中使用 javascript 启动自定义协议处理程序?
【发布时间】:2021-08-25 17:44:59
【问题描述】:

我正在尝试通过 Javascript 在 Chrome 中启动自定义协议处理程序。我可以启动应用程序,但这样做会创建一个弹出窗口,然后触发弹出窗口阻止程序。无论如何在没有弹出窗口的情况下启动应用程序?窗口关闭,但仍被视为弹出窗口。

这是我当前的代码:

    function setBrowser() {
        var userAgent = navigator.userAgent.toLowerCase();
        if (userAgent.indexOf("chrome") > -1) {
            //If Chrome launch without ActiveX involved
            var url = 'ABCProcessLaunch:-Domain mydomain -Args http://google.com -requirelogin true -method "chrome"';            
            setTimeout(window.close, 10);
            window.open(url, '_blank');
        }
    }

【问题讨论】:

标签: javascript google-chrome protocol-handler


【解决方案1】:

我从您对window.close 的电话推断,这可能就是您首先需要在新窗口中打开链接的原因。

您可能会在 <iframe> 元素中打开自定义 URL 方案。这样,您的setTimeout 呼叫仍会在 10 秒后触发:

function setBrowser() {
    var userAgent = navigator.userAgent.toLowerCase();
    if (userAgent.indexOf("chrome") > -1) {
        //If Chrome launch without ActiveX involved
        var url = 'ABCProcessLaunch:-Domain mydomain -Args http://google.com -requirelogin true -method "chrome"';   
        var iframe = document.createElement("iframe");
        iframe.src = url;         
        setTimeout(window.close, 10);
        document.querySelector("body").appendChild(iframe);
    }
}

【讨论】:

  • 我试过那个方法。它仍然作为“弹出窗口”被阻止如果我允许该站点,那么这两种方法都可以工作,我试图找到一种方法来避免需要在 Chrome 中添加到允许的站点。
猜你喜欢
  • 1970-01-01
  • 2011-10-28
  • 2021-02-15
  • 2015-05-20
  • 2013-12-22
  • 2011-09-05
  • 2015-11-10
  • 1970-01-01
相关资源
最近更新 更多