Perfectly compatible with IE chrome ff set as home page add to favorites and save to desktop js code
- 2020-05-07 19:11:56
- OfStack
Today I would like to share with you 1 set as the home page, favorite site and saved to the desktop js code, very practical.
<script type="text/javascript">
// Set to the home page
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 "And press enter and then will [signed.applets.codebase_principal_support] Set to 'true'");
}
}else{
alert(" Sorry, the browser you are using is unable to complete this operation. \n\n You need to manually "+url+" Set as home page. ");
}
}
}
// Collect 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 is unable to complete this operation. \n\n Join collection failed, please use Ctrl+D 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:
<a href="javascript:void(0);" onclick="SetHome(this,'http://www.xyz.com');"> Set to the home page </a>
<a href="javascript:void(0);" onclick="AddFavorite(' My website ',location.href)"> Collect this site </a>
<a href="javascript:void(0);" onclick=" toDesktop(location.href . ' My website ')"> Save to desktop </a>
This is from my website down drip, you rest assured use.