[读书笔记][JavaScript权威指南(第四版)][cookie]
//构造函数:用指定的名字和可选的性质为指定的文档创建一个cookie对象。
//参数:
// doucment:保存cookie的Document对象
// name: 指定cookie名的字符串
// hours: Number,指定从现在起到cookie过期的小时数
// path: String,指定cookie的路径性质
// domain: String, 指定cookie的域性质
// secure: Boolean,true,则需要安全的cookie
function Cookie(document,name,hours,path,domain,secure)
{
//该对象所有预定义的属性都以'
开头。
//这是为了与存储在cookie中的属性值区别开。
this.$document=document;
this.$name=name;
this.$expiration=(hours)?new Date((new Date()).getTime+hours*3600000):null;
this.$path=(path)?path:null;
this.$domain=(domain)?domain:null;
this.$secure=(secure)?true:false;
}
Cookie.prototype.store=function(){
//首先遍历cookie对象的属性,并且将cookie值链接起来
//由于cookie将等号和分好作为分隔符
//所以我们使用冒号和&来分隔存储在单个cookie值中的状态变量。
var cookieval='';
for(var prop in this){
if((prop.charAt(0)=='
||(typeof this[prop]=='function'))
continue;
if(cookieval!="")
cookieval+='
;
cookieval+=prop+':'+escape(this[prop]);
}
//连接完整的cookie值
//其中包括名字和创建cookie对象时指定的各种性质
var cookie=this.$name+'='+cookieval;
if(this.$expiration)
cookie+=';expirse='+this.$expiration.toGMTString();
if(this.$path)
cookie+=';path='+this.$path;
if(this.$domain)
cookie+=';domain'+this.$domain;
if(this.$secure)
cookie+=';secure'+this.$secure;
//设置Document.cookie属性来保存cookie
this.$document.cookie=cookie;
}
//该函数是cookie对象的load()方法
Cookie.prototype.load=function(){
//首先得到属于该文档的所有cookie的列表
//通过读Document.cookie属性可以实现
var allcookies=this.$document.cookie;
if(allcookies=="")
return false;
//下面从该列表中提取已命名的cookie
var start=allcookies.indexOf(this.$name+'=');
if(start==-1) //该页未定义cookie
return false;
start+=this.$name.length+1; //跳过名字和等号
var end=allcookies.indexOf(';',start)
相关文档:
javascript设计模式第一张有一个有趣的实现继承的方法,当然javascript本质上是实现继承,还不是典型意义上的"is-a"的逻辑继承或者说是语义继承。基本的方法就是通过function的prototype属性。
一,很简单的方法
<script type="text/javascript">
<!--
var Anim = function(){ ......
Javascript代码
<script>
var idTmr = "";
function copy(tabid){
var oControlRange = document.body.createControlRange();
oControlRange.add(tabid,0);
oControlR ......
出处:http://www.jcwcn.com/article/2005/1210/javascript_17476.html
<HTML>
<HEAD>
<title>WEB页面导出为EXCEL文档的方法
</title>
</HEAD>
<body>
<BR>
<table id = "PrintA" width="100%" border="1" cell ......
//各种尺寸
s += "\r\n网页可见区域宽:"+ document.body.clientWidth;
s += "\r\n网页可见区域高:"+ document.body.clientHeight;
s += "\r\n网页可见区域高:"+ document.body.offs ......
1.如何在javascript访问C#变量
方法一:使用<%=%>
<input id="Button3" type="button" value="js调用c#变量" onclick="return Button3_onclick()" />
function Button3_onclick()
{
alert('我的名字:'+ '<%=name %>'); ......