最简单的跨浏览器检查协议处理程序是否已注册 [英] simplest cross-browser check if protocol handler is registered
问题描述
当用户点击自定义协议链接时(例如 myapp:// superlink
)
When user clicks link with custom protocol (like myapp://superlink
)
我需要启动应用程序或允许用户下载和运行配置应用程序
I need either launch an app or allow user to download and run configuration app
我正在寻找跨浏览器方式来检查自定义协议是否已注册
I am looking for cross-browser way to check if custom protocol is registered
我试图通过检查用户代理服务器端(对于IE)来确定这一点
I've tried to determine this by checking user agent server-side (for IE)
[HKEY_LOCAL_MACHINE \ SOFTWARE \Wow6432Node\Microsoft\Windows\CurrentVersion \Internet
设置\5.0 \用户代理\ Post平台]myapp=
[HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Internet Settings\5.0\User Agent\Post Platform] "myapp"=""
发送
`....NET CLR 3.0.30729; .NET4.0C; .NET4.0E; InfoPath.3; **myapp**`
作为用户代理
这是好的,干净的方式,简单的配置:
This is good, clean way, easy configuration:
只需下载.reg文件并运行它或通过ms windows策略传播
just download .reg file and run it or propagiate via ms windows policy
我无法为Chrome和Firefox修复此问题
I can't fix this for Chrome and Firefox
是否有任何客户端解决方案(以js为单位)?
Are there any client-side solution (in js)?
我的环境:IE8 +,Chrome(最新),Firefox(最新)
My enviroment: IE8+, Chrome (latest), Firefox(latest)
推荐答案
这个老技巧总是让我失望。
There is this old tricks that it always never fails me.
你需要的核心功能是 setTimeout
。我会详细告诉你:
The core functionality that you need is setTimeout
. I will tell you in detail:
setTimeout(function() {
window.location = "http://itunes.com/app/yourapplocation";
}, 200);
// once you do the custom-uri, it should properly execute the handler, otherwise, the settimeout that you set before will kick in
window.location = "myapp://superlink";
现在你提到它可能是一个链接或链接所以我为了你的方便我做了这个很好的功能:
Now you mentioned that it maybe a link or links so I made this nice function just for your convenience:
HTML代码
<a href="myapp://superlink" data-href-alt="http://itunes.com/app/yourapplocation">Click here</a>
JS代码
$("a[href*='myapp://']").click(function(e)
{
var el = $(this);
setTimeout(function() {
window.location = el.data("data-href-alt");
}, 200);
// once you do the custom-uri, it should properly execute the handler, otherwise, the settimeout that you set before will kick in
window.location = el.data("href");
e.preventDefault();
});
希望这会帮助你
:)
Hope this will help you :)
这篇关于最简单的跨浏览器检查协议处理程序是否已注册的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!