Mar 25

设为首页,加入收藏,设为桌面快捷方式JS代码 不指定

设为首页,加入收藏,设为桌面快捷方式:

var title ="系统名称";
var url = window.location.href;
function checkLogin() {
  if (document.getElementById("j_username").value == "") {
    alert("请输入用户名!");
    document.getElementById("j_username").focus();
    return false;
  }
  if (document.getElementById("j_password").value == "") {
    alert("请输入密码!");
    document.getElementById("j_password").focus();
    return false;
  }
  return true;
}
// 加入收藏
function addBookmark() {
  if (window.sidebar) {
    window.sidebar.addPanel(title, url, "");
  } else if (document.all) {
    window.external.AddFavorite(url, title);
  } else if (window.opera && window.print) {
    return true;
  }
}
//设为首页
function setHomepage() {
  if (document.all) {
    document.body.style.behavior = 'url(#default#homepage)';
    document.body.setHomePage(url);
  } else if (window.sidebar) {
    if (window.netscape) {
      try {
        netscape.security.PrivilegeManager
            .enablePrivilege("UniversalXPConnect");
      } catch (e) {
        alert("该操作被浏览器拒绝,如果想启用该功能,请在地址栏内输入 about:config,然后将项 signed.applets.codebase_principal_support 值该为true");
      }
    }
    var prefs = Components.classes['@mozilla.org/preferences-service;1']
        .getService(Components.interfaces.nsIPrefBranch);
    prefs.setCharPref('browser.startup.homepage', title);
  }
}

//保存桌面快捷方式
function toDesktop() {
  try {
    var WshShell = new ActiveXObject("WScript.Shell");
    var oUrlLink = WshShell.CreateShortcut(WshShell
        .SpecialFolders("Desktop")
        + "\\" + title + ".url");
    oUrlLink.TargetPath = url;
    oUrlLink.Save();
    alert("已成功加入桌面快捷方式!");
  } catch (e) {
    saveDesktop();
    // alert("当前浏览器安全级别不允许操作!");
  }
}

//使用保存为文件方式
function saveDesktop() {
  document.getElementById("furl").value = url;
  document.getElementById("fname").value = title;
  document.getElementById("shortcuts").submit();
}


快捷方式代码:

[InternetShortcut]
URL=http://www.163.com
Add a comment

Nickname

Site URI

Email

Enable HTML Enable UBB Enable Emots Hidden Remember [Login] [Register]