JavaScript puts the webpage on the desktop and sends a shortcut to the desktop

No nonsense, go directly to the code, there are comments and explanations in the code!

Note: ActiveXObject only supports IE browser, so this function on the desktop only supports IE browser, not Firefox browser, Google browser, etc.!


<%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Put it on the desktop, send a shortcut to the desktop</title>
<link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/css/body.css">
<link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/css/mark.css">
<link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/css/console.css">
<script type="text/javascript" src="${pageContext.request.contextPath}/js/console.js"></script>
</head>
<body>
	<center>
		<h2>Put it on the desktop and send a shortcut to the desktop (IE browser will display the button to the desktop, other browsers will not display the button to the desktop)</h2>
		<input id="toDesktopButton" type="button" value="put on desktop" onclick="toDesktop(location.href, 'Snow Leopard Software Studio')">
	</center>
</body>
<script type="text/javascript">

	//Send the shortcut to the desktop
	function toDesktop (sUrl, sName) {
		try {
			var WshShell = new ActiveXObject("WScript.Shell");
			var oUrlLink = WshShell.CreateShortcut(WshShell
					.SpecialFolders("Desktop")
					+ "\\" + sName + ".url");
			oUrlLink.TargetPath = sUrl;
			oUrlLink.Save();
			alert("Successfully created desktop shortcut!");
		} catch (e) {
			alert("The current IE security level does not allow operation or your browser does not support this function!");
		}
	}
	
	/ / Determine whether it is an IE browser
	function isIE () {
		if (!!window.ActiveXObject || "ActiveXObject" in window) {
// alert("It's IE browser");
			return true;
		} else {
// alert("Not IE browser");
			return false;
		}
	}
	
	//Execute the function after the entire page is loaded
	window.onload = function() {
		var result = isIE ();
		if (!result) {
			//not IE browser
			//get button element
			var toDesktopButtonNode = document.getElementById("toDesktopButton");
			// hide button
			toDesktopButtonNode.style.display = "none";
		}
	}
</script>
</html>

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325626038&siteId=291194637