Home > Web Front-end > JS Tutorial > body text

JS code for setting as homepage and adding to favorites (multi-browser support)_javascript skills

WBOY
Release: 2016-05-16 17:46:56
Original
1601 people have browsed it

The latest code that supports IE, firefox and chrome with prompt information:

<script type="text/javascript">
//设为首页 www.jb51.net
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("抱歉,此操作被浏览器拒绝!
\n请在浏览器地址栏输入“about:config”并回车然后将[signed.applets.codebase_principal_support]设置为'true'");
     }
    }else{
    alert("抱歉,您所使用的浏览器无法完成此操作。
\n您需要手动将【"+url+"】设置为首页。");
    }
 }
}
 
//收藏本站 www.jb51.net
function AddFavorite(title, url) {
 try {
   window.external.addFavorite(url, title);
 }
catch (e) {
   try {
    window.sidebar.addPanel(title, url, "");
  }
   catch (e) {
     alert("抱歉,您所使用的浏览器无法完成此操作。
\n加入收藏失败,请进入新网站后使用Ctrl+D进行添加");
   }
 }
}
</script>
<a href="javascript:void(0);" onclick="SetHome(this,'http://www.jb51.net');">设为首页</a>
<div class="text text2"><a href="javascript:void(0);" onclick="AddFavorite('脚本之家','http://www.jb51.net')">收 藏 本 站</a>
Copy after login

First share two js codes for setting up the home page (if it does not meet the standards, we will not talk about compatibility):

There are two ways to set the current page as the homepage of your browser. One is to set the webpage you are browsing as the homepage; the other is to set the specified URL as the homepage. As for which one you use, it depends on your needs. , each has its own applicable occasions.

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template