在Windows操作系统中,我有一个自定义URI方案,它用于
IE,Firefox,Opera,Safari,Google Chrome
启动Juniper路由器VPN SSH客户端(如Cisco)。基本上,如果安装了SSH客户端,可以从网页VPN SSH客户端启动SSH客户端。
<a href="juniper:open"> VPN SSH Client </a>问题:
有时用户没有从CD/DVD盒安装Juniper路由器SSH客户端应用程序,因此juniper:open什么也不做。
因此,在这种情况下,我需要检测天气是否有URL方案可用。
因此,我尝试了Javascript方法,但它不能准确地工作。因为juniper:open实际上不是web链接。
那我怎么才能检测到呢?
<script>
// Fails
function test1(){
window.location = 'juniper:open';
setTimeout(function(){
if(confirm('Missing. Download it now?')){
document.location = 'https://www.junper-affiliate.com/setup.zip';
}
}, 25);
//document.location = 'juniper:open';
}
// Fails
function test2(h){
document.location=h;
var time = (new Date()).getTime();
setTimeout(function(){
var now = (new Date()).getTime();
if((now-time)<400) {
if(confirm('Missing. Download it now?')){
document.location = 'https://www.junper-affiliate.com/setup.zip';
} else {
document.location=h;
}
}
}, 300);
}
</script>然后:
<a onclick="test1()">TEST 1</a>
<a href="juniper:open" onclick="test2(this.href);return false;">TEST 2</a>发布于 2014-07-04 10:13:24
编辑注释中的建议如下:
function goto(url, fallback) {
var script = document.createElement('script');
script.onload = function() {
document.location = url;
}
script.onerror = function() {
document.location = fallback;
}
script.setAttribute('src', url);
document.getElementsByTagName('head')[0].appendChild(script);
}和
<a href="javascript:" onclick="goto('juniper:open', 'https://www.junper-affiliate.com/setup.zip');">TEST 2</a> 您必须付出的代价,是对页面的重复要求。
编辑
对于相同来源的策略来说,这是一个很好的解决方案,它阻止使用XMLHTTPRequest的异步版本正常工作,因为SOP将跨域请求限制在http和juniper上:因此,open总是失败的。
function goto(url, fallback) {
var xmlhttp = new XMLHttpRequest();
xmlhttp.open('GET', url, false);
try {
xmlhttp.send(null); // Send the request now
} catch (e) {
document.location = fallback;
return;
}
// Throw an error if the request was not 200 OK
if (xmlhttp.status === 200) {
document.location = url;
} else {
document.location = fallback;
}
}编辑
下面的初始解决方案实际上不起作用,因为如果不支持协议,则不会抛出任何异常。
try {
document.location = 'juniper:open';
} catch (e) {
document.location = 'https://www.junper-affiliate.com/setup.zip';
}发布于 2014-07-07 08:58:45
经过大量的搜索,我还没有找到任何能帮助我解决问题的方法。但这就是我现在要做的
1)编写一个小型的小型for服务器,可以在开机和崩溃时24/7在PC机上运行。使用本机python:
python -m SimpleHTTPServer [port]2)微型get服务器将监听异常端口,如10001或从未被使用的TCP端口。
3)在浏览器中,我们必须与http://localhost:10001通信才能得到答复
4)根据这一答复,我们必须决定
否则就没办法了
编辑:或者你可以这样做:InnoSetup - Is there any way to manually create cookie for Internet explorer?
https://stackoverflow.com/questions/24571548
复制相似问题