jquery收藏本站代码 带cookies判断
//jQuery.cookie 插件
jQuery.cookie = function(name, value, options) {
if (typeof value != ‘undefined’) { // name and value given, set cookie
options = options || {};
if (value === null) {
value = ”;
options.expires = -1;
}
var expires = ”;
if (options.expires && (typeof options.expires == ‘number’ || options.expires.toUTCString)) {
var date;
if (typeof options.expires == ‘number’) {
date = new Date();
date.setTime(date.getTime() + (options.expires * 24 * 60 * 60 * 1000));
} else {
date = options.expires;
}
expires = ‘; expires=’ + date.toUTCString(); // use expires attribute, max-age is not supported by IE
}
// CAUTION: Needed to parenthesize options.path and options.domain
// in the following expressions, otherwise they evaluate to undefined
// in the packed version for some reason…
var path = options.path ? ‘; path=’ + (options.path) : ”;
var domain = options.domain ? ‘; domain=’ + (options.domain) : ”;
var secure = options.secure ? ‘; secure’ : ”;
document.cookie = [name, ‘=’, encodeURIComponent(value), expires, path, domain, secure].join(”);
} else { // only name given, get cookie
var cookieValue = null;
if (document.cookie && document.cookie != ”) {
var cookies = document.cookie.split(‘;’);
for (var i = 0; i < cookies.length; i++) {
var cookie = jQuery.trim(cookies[i]);
// Does this cookie string begin with the name we want?
if (cookie.substring(0, name.length + 1) == (name + ‘=’)) {
cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
break;
}
}
}
return cookieValue;
}
};
//收藏本站代码
$(function(){
jQuery.fn.addCollect = function(l, h){
return this.click(function(){
var t = jQuery(this);
if(jQuery.browser.msie) {
window.external.addFavorite(h, l);
} else if(jQuery.browser.mozilla || jQuery.browser.opera){
t.attr(“rel”, “sidebar”);
t.attr(“title”, l);
t.attr(“href”, h);
} else{
alert(“您的是神马浏览器啊?请使用Ctrl+D将本页加入收藏夹!”);
}
});
}
$(“.collectIn”).addCollect(“胡搞吧-让我们一起非诚互搞吧!”, window.location.href);
var COOKIE_NAME = “collect”;
if( $.cookie(COOKIE_NAME)){$(“.collect”).hide();}else{
$(“.collect”).show();
}
$(“.collectOff,.collectIn”).click(function(){
$(“.collect”).slideUp().remove();
$.cookie(COOKIE_NAME, ‘collect’, { path: ‘/’, expires: 30 });
})
})
转载请注明:jquery收藏本站代码 带cookies判断 - 编程知识库
下一篇:慎用设计手段解决需求问题
您可能还会对这些文章感兴趣
2016-12-20 1,786次只会用jQuery前端到底low不low?
如果你之前没有看过我的《前端工程师如何月薪过4万》这里建议大家仔细读读一下,因为里面有整个前端工程师成长的技术路线图和我的故事。同时很多小伙伴问我的学历后来没再考考么,我是考了成考的北京航空航天大学,也马上快毕业了。不过我觉得这件事不足为提,因为国...
2016-12-17 721次jquery的$().each,$.each的区别
在jquery中,遍历对象和数组,经常会用到$().each和$.each(),两个方法。两个方法是有区别的,从而这两个方法在针对不同的操作上,显示了各自的特点。 $().each,对于这个方法,在dom处理上面用的较多。如果页面有多个input标签类型为checkbox,对于这时用$().each来...
2016-12-15 1,853次jquery加载外部文件(.txt .html)显示在网页上
在web开发中常常需要用到jquery去动态的加载文件显示在网页上面,下面是实现的小方法,希望给大家一点提示,达到抛砖引玉的作用哦!!! 效果图: 要加载显示的文件: 网页加载效果: html代码截图: jquery代码截图: 转载请注明:jquery加载外部文件(.txt ....
2016-12-15 665次javascript实现网页倒计时
web开发中常常需要使用到网页倒计时功能,下面是实现方法: 效果图: 代码截图: 转载请注明:javascript实现网页倒计时 - 编程知识库
大家正在看
- linux 系统中Mysql 进程占用cpu过高的解决
- 二类电商是什么意思? 二类电商有哪些?暴利二类电商还好做吗?
- 【二类电商广点通投放指南】二类电商广点通投放值不值
- 密码保护:支付宝突破微信封锁唤起支付宝代码
- Host is not allowed to connect to this MySQL server解决方法
- 密码保护:移动端js自动复制代码
- linux数据库调优,WordPress MySQL占用cpu高数据库优化
- 2017 年十大网页设计趋势
- 网页端的VR实现离我们还远么?
- 最完整的Chrome浏览器客户端调试大全
- iPhone用户人均每天遭电话骚扰1次
- 3G电子化销售服务系统
- Java WeakReference的理解与使用
- 搞清楚 Python traceback