JS实现设为首页与加入收藏
<script type="text/javascript">
// 设置为主页
function SetHome(obj, vrl) {
try {
obj.style.behavior = 'url(#default#homepage)'; obj.setHomePage(vrl);
}
catch (e) {
if (window.netscape) {
try {
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
}
catch (e) {
alert("此操作被浏览器拒绝!\n请在浏览器地址栏输入“about:config”并回车\n然后将 [signed.applets.codebase_principal_support]的值设置为'true',双击即可。");
}
var prefs = Components.classes['@mozilla.org/preferences-service;1'].getService(Components.interfaces.nsIPrefBranch);
prefs.setCharPref('browser.startup.homepage', vrl);
} else {
alert("您的浏览器不支持,请按照下面步骤操作:1.打开浏览器设置。2.点击设置网页。3.输入:" + vrl + "点击确定。");
}
}
}
// 加入收藏 兼容360和IE6
function shoucang(sTitle, sURL) {
try {
window.external.addFavorite(sURL, sTitle);
}
catch (e) {
try {
window.sidebar.addPanel(sTitle, sURL, "");
}
catch (e) {
alert("加入收藏失败,请使用Ctrl+D进行添加");
}
}
}
</script>
调用如下:
<a href="javascript:void(0)" onclick="SetHome(this,window.location)">设为首页</a> <img src="data:images/02.jpg" /><a href="javascript:void(0)" onclick="shoucang(document.title,window.location)">加入收藏</a>
还有第二种方法:
<a href="#" onclick="this.style.behavior='url(#default#homepage)';this.setHomePage(document.location.href);event.returnValue=false;">设为首页</a>兼容360和IE
<a href="Javascript:window.external.addFavorite(document.location.href,document.title)">加入收藏</a>只适用于IE
JS实现设为首页与加入收藏的更多相关文章
- js代码 设为首页 加入收藏
// JavaScript Document // 加入收藏 <a onclick="AddFavorite(window.location,document.title)" ...
- js 设为首页、加入收藏
// 加入收藏 <a onclick="AddFavorite(window.location,document.title)">加入收藏</a>func ...
- 完美兼容IE,chrome,ff的设为首页、加入收藏及保存到桌面js代码
<script type="text/javascript"> //设为首页 function SetHome(obj,url){ try{ ...
- 设为首页 添加到收藏夹 (share)
设为首页,添加到收藏夹 分享自:http://my.oschina.net/lyx2012/blog/60036 设为首页 和 收藏本站js代码 兼容IE,chrome,ff <script t ...
- [代码收藏]设为首页和加入收藏的JavaScript代码(兼容多浏览器)
其实不少非IE内核浏览器都仍不支持通过代码将网页设为主页和加入收藏的功能,因此说是兼容,其实只是一个try,catch后的提醒而已. 加入收藏: /* * author : 2010-12-27 11 ...
- javascript设为首页、加入收藏
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- 原生js编写设为首页兼容ie、火狐和谷歌
// JavaScript Document // 加入收藏 <a onclick="AddFavorite(window.location,document.title)" ...
- 兼容IE,chrome,ff的设为首页、加入收藏及保存到桌面
// JavaScript Document// 加入收藏 < a onclick="AddFavorite(window.location,document.title)" ...
- HTML设为首页/加入收藏代码
(特别注意:要把'这个符号换成无任何输入法状态中输入的'这个符号,否则程序无法运行) 1.文字型: <a onclick="this.style.behavior='url ...
随机推荐
- [Monitor] 监控规则定义
系统监控规则:
- 关于ICE
转自:http://wenda.chinabaike.com/b/38322/2013/1103/614756.html 一.ICE产生的背景 基于信令协议的多媒体传输是一个两段式传输.首先,通过信令 ...
- 外键为','(逗号)拼接ID,连接查询外键表ID
select distinct pipeId=substring(a.PipeIn,b.number,charindex(',',a.PipeIn+',',b.number)-b.number) fr ...
- 1.CoreLocation 使用,获取当前位置
1. ios7只要开始定位,系统就会自动要求你对应用程序授权 ios8之后,必须要代码中实现要求用户对应用程序授权 ,在plist中添加以下两个属性 NSLocationWhenInUseDescri ...
- 图说设计模式(UML和设计模式)
https://github.com/me115/design_patterns http://design-patterns.readthedocs.org/zh_CN/latest/index.h ...
- Android的Touch事件处理机制
Android的Touch事件处理机制比较复杂,特别是在考虑了多点触摸以及事件拦截之后. Android的Touch事件处理分3个层面:Activity层,ViewGroup层,View层. 首先说一 ...
- Ubuntu 14.04下翻译软件的安装与比较
转载:sixipiaoyang.blog.163.com/blog/static/6232358820144146386437/
- ASP.NET MVC使用过滤器进行权限控制
1.新建MVC项目 2.找到Models文件夹,新建 LoginCheckFilterAttribute 类 public class LoginCheckFilterAttribute : Acti ...
- Codeforces Round #356 (Div. 2)-B
B. Bear and Finding Criminals 链接:http://codeforces.com/contest/680/problem/B There are n cities in B ...
- 插入视频(youtube)
iframe 如果没有flash播放器,会自动使用html5播放器 <iframe width="420" height="315" src=" ...