Today I will share with you a piece of js code set as homepage, bookmark this site and save it to the desktop, which is very practical.
The code copy is as follows:
<script type="text/javascript">
//Set as homepage
function SetHome(obj,url){
try{
obj.style.behavior='url(#default#homepage)';
obj.setHomePage(url);
}catch(e){
if(window.netscape){
try{
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
}catch(e){
alert("Sorry, this operation was rejected by the browser! /n/n Please enter "about:config" in the browser address bar and press Enter and then set [signed.applets.codebase_principal_support] to 'true'");
}
}else{
alert("Sorry, the browser you are using cannot do this. /n/n You need to manually set ["+url+"] to the homepage.");
}
}
}
//Save this site
function AddFavorite(title, url) {
try {
window.external.addFavorite(url, title);
}
catch (e) {
try {
window.sidebar.addPanel(title, url, "");
}
catch (e) {
alert("Sorry, the browser you are using cannot complete this operation. /n/n failed to add to favorites, please use Ctrl+D to add");
}
}
}
//Save to 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();
}
catch(e) {
alert("The current IE security level does not allow operation!");
}
}
</script>
Page call:
The code copy is as follows:
<a href="javascript:void(0);" onclick="SetHome(this,'http://www.xyz.com');">Set as homepage</a>
<a href="javascript:void(0);" onclick="AddFavorite('My Website',location.href)">Save this site</a>
<a href="javascript:void(0);" onclick=" toDesktop(location.href, 'My Site')">Save to desktop</a>
This is taken from my website, please feel free to use.