ajax – 可以使用Google Chrome打开自定义网址方案吗?
我在Mac OS X中注册了与第三方应用程序管理的方案(如http)。
即,x-someapp://某种行为或类似的东西。 如何使用Google Chrome浏览器打开此网址? Safari推出了一些注册的应用程序。这是对的。 Firefox和Opera询问要做什么…我也可以启动App。 但Chrome …不问。 我甚至试图用JavaScript里面写一些HTML页面来发送XHttpRequest: function _httpExecuteCallback() { if (httpRequestCallbackFunction != null) { if (httpRequest.readyState == 4) { if (httpRequest.status == 200) { httpRequestCallbackFunction(); httpRequestCallbackFunction = null; } } } } function _httpGet(url,callbackFunction) { httpRequest = false; httpRequestCallbackFunction = callbackFunction; httpRequest = new XMLHttpRequest(); httpRequest.onreadystatechange = _httpExecuteCallback; httpRequest.open('GET',url,true); httpRequest.send(null); } _httpGet('x-someapp://test',function(){}) 没有结果…
当前接受的解决方案对于Chrome for SSL https有问题。观看控制台日志时,Chrome会阻止该请求,因为它认为自定义网址协议不安全:
[blocked] The page at reports blah blah ran insecure content from customproto//blah blah 这是一个解决方案(这需要我几天的研究): <input type='button' value='Test Custom Url' onclick='exec()'> <script> function submitRequest(buttonId) { var d = (window.parent)?window.parent.document:window.document if (d.getElementById(buttonId) == null || d.getElementById(buttonId) == undefined) return; if (d.getElementById(buttonId).dispatchEvent) { var e = d.createEvent("MouseEvents"); e.initEvent("click",true,true); d.getElementById(buttonId).dispatchEvent(e); } else { d.getElementById(buttonId).click(); } } function exec(){ var d = (window.parent)?window.parent.document:window.document var f = d.getElementById('customUrlLink') if (f ) {f.parentNode.removeChild(f);} var a = d.createElement('a'); a.href = 'mycustomproto://arg1'; a.innerHTML = "Link" a.setAttribute('id','customUrlLink'); a.setAttribute("style","display:none; "); d.body.appendChild(a); submitRequest("customUrlLink"); } </script> 这个代码不适用于IE。我发现使用这种技术IE将自定义协议的参数限制为小于1000,其中使用iFrame技术IE将允许2083个字符。 克服javascript中url限制的唯一方法是吸收数据并多次调用。如果有人想要刺伤,请让我知道它是怎么回事。我想用它。 要在执行的应用程序中处理长URL,请将令牌传递到应用程序中,并从URL获取数据。 所以现在我使用一个功能Chrome / FF和另一个功能的IE。 这些链接帮助我开发了这个解决方案: https://superuser.com/questions/655405/custom-protocol-handler-not-working-in-chrome-on-ssl-page Simulating a click in jQuery/JavaScript on a link (希望我几天前知道这一点….希望这有助于某人) ================================================== 更新:(8小时以后) ================================================== Jake为chrome提供了一个很棒的解决方案:https://superuser.com/questions/655405/custom-protocol-handler-not-working-in-chrome-on-ssl-page 这只适用于铬: window.location.assign("customprotocol://"); 它会在iframe中失败,所以这是正常工作: var w = (window.parent)?window.parent:window w.location.assign(service + '://' + data) ================================================== 更新:(周后) ================================================== 打开自定义协议的所有示例,包括我自己的,在URL中都有一个“://”。这正是导致SSL警告的原因。 结果解决的办法是将“://”改为“:” 这样做: src="x-myproto:query" ..... SSL警告将会消失。 ================================================== 关注:(经过几个月的生产使用) ================================================== 这一直很好用于歌声。检测浏览器,如果chrome执行此操作: var w = (window.parent)?window.parent:window w.location.assign('myproto://xyzabcdefetc') 对于IE和其他浏览器,我做点略有不同。 请注意,浏览器对您可以在自定义url协议中放置多少数据施加限制。只要您的字符串低于800个字符,这似乎是在所有浏览器中工作的魔术数字。 (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |