我使用的是asp.net MVC4 Web应用程序,如果客户端机器尚未安装,我需要从ftp 安装软件。在安装过程中将一些数据写入客户端计算机的注册表,例如:
Test
|__DefaultIcon
|__Shell
|__Open
|__command
此条目仅在安装软件后才会出现。所以我可以在下次有人尝试下载软件时自动初始化软件,机器已经有软件。 要使用以下代码初始化软件:
<script type="text/javascript">
function LaunchURLScript() {
var url = "Test:";
// Creates an object which can read files from the server
var reader = new XMLHttpRequest();
// Opens the file and specifies the method (get)
// Asynchronous is true
reader.open('GET', url, true);
//check each time the ready state changes
//to see if the object is ready
reader.onreadystatechange = checkReadyState;
function checkReadyState() {
if (reader.readyState === 4) {
//check to see whether request for the file failed or succeeded
if ((reader.status == 200) || (reader.status == 0)) {
//page exists -- redirect to the checked
//checked for page
// document.location.href = url;
window.open(url);
self.focus();
}
else {
alert("456");
//does nothing and quits the function
//if the url does not exist
return;
}
}//end of if (reader.readyState === 4)
}
// end of checkReadyState()
// Sends the request for the file data to the server
// Use null for "get" mode
try{
reader.send(null);
}
catch (err) {
alert(err.message);
}
}
</script>
但问题是window.open(url)会在url不存在的情况下显示,这意味着没有安装软件。请在调用window.open(url)之前帮助找出url是否存在