当用户单击带有自定义协议的链接时(例如myapp://superlink
)
我需要启动应用程序或允许用户下载并运行配置应用程序
我正在寻找跨浏览器的方法来检查自定义协议是否已注册
我试图通过检查用户代理服务器端(对于 IE)来确定这一点
[HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Internet
设置\5.0\用户代理\发布平台]“myapp”=“”
sends
`....NET CLR 3.0.30729; .NET4.0C; .NET4.0E; InfoPath.3; **myapp**`
作为用户代理
这是很好的、干净的方式、简单的配置:
只需下载 .reg 文件并运行它或通过 MS Windows 策略传播
我无法修复 Chrome 和 Firefox 的此问题
有没有客户端解决方案(js)?
我的环境:IE8+、Chrome(最新)、Firefox(最新)
有一个老把戏,它永远不会让我失望。
您需要的核心功能是setTimeout
。我来详细告诉你:
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";
现在你提到它可能是一个或多个链接,所以我做了这个很好的功能只是为了你的方便:
HTML代码
<a href="myapp://superlink" data-href-alt="http://itunes.com/app/yourapplocation">Click here</a>
JS code
$("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();
});
希望对你有帮助
:)
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)