Inscripción: A menudo necesitamos implementar un acceso directo en el escritorio en la página de inicio de nuestro sitio web en nuestro trabajo, entonces, ¿cómo lo hacemos?
visualización de imagen:
Código:
El primer paso: obtener la ruta y el nombre del título;
sName: document.title,
sUrl: window.location.href
El segundo paso: determinar si es un navegador IE;
isIE() {
if (!!window.ActiveXObject || "ActiveXObject" in window) {
// this.$message({
// message: '是IE浏览器',
// type: 'warning'
// })
return true;
} else {
// alert("不是IE浏览器");
this.$message({
message: '如需生成桌面快捷方式,请在IE浏览器中打开!',
type: 'warning'
})
return false;
}
},
Nota: utilice ActivexObject para distinguir entre navegadores IE y navegadores que no son IE
IE admite el control ActiveObject, pero la serie Chrome no lo admite
El tercer paso: ajustar la interfaz
toDesktop() {
var result = this.isIE();
if (!result) {
//不是IE浏览器
//获得按钮元素
var toDesktopButtonNode = document.getElementById("toDesktopButton");
//隐藏按钮
// toDesktopButtonNode.style.display = "none";
return false
}
let sUrl = this.sUrl
let sName = this.sName
console.log('result', sUrl, sName)
try {
var WshShell = new ActiveXObject("WScript.Shell");
// CreateShortcut 方法创建 WshShortcut 对象并将其返回。如果快捷方式标题以 .url 结尾,就会创建 WshURLShortcut 对象。
// SpecialFolders 使用 WshSpecialFolders 对象提供对 Windows shell 文件夹的访问,如桌面文件夹,开始菜单文件夹和个人文档文件夹。
// 返回完整的Windows桌面文件夹路径,
var oUrlLink = WshShell.CreateShortcut(WshShell
.SpecialFolders("Desktop")
+ "\\" + sName + ".url");
oUrlLink.TargetPath = sUrl;
oUrlLink.Save();//保存一个快捷方式,该快捷方式指向 FullName 属性指定的位置。
this.$notify({
type: 'success',
message: '成功创建桌面快捷方式!'
})
} catch (e) {
this.$message({
message: '当前IE安全级别不允许操作或您的浏览器不支持此功能!',
type: 'warning'
})
}
},
Observaciones: La ayuda del método createShortcut() es clave.
¡Dale me gusta si te gusta! ! !