js读取Cookies

来源:百度知道 编辑:UC知道 时间:2024/09/23 17:26:46
asp.net的js,想读Cookies中的user.UserID的值,把值加在下面JS代码中的case "xxx" :url="后面,应该如何改写?请教高手!谢谢!

fav = function(){
};

fav.open = function(site){
var url;
var d=parent.document;
var c_href=d.location.href;
var c_title=d.title;
var c_sel;

if (d.selection){
c_sel = d.selection.type!='None'?d.selection.createRange().text:''
}else{
c_sel = d.getSelection?d.getSelection():'';
}
if (c_sel.length>1500){
c_sel=c_sel.substr(0,1500);
}

switch(site){
case "xxx" :
url="http://xxx.com/store.asp?title="+escape(c_title)+"&u="+escape(c_href)+"&n="+escape(c_sel);
window.open(url,'zcfw','scrollbars=no,width=600,height=450,left=80,top=80,status=yes,resizable=yes');
break;

简单读取
var the_cookie = document.cookie;
var broken_cookies = the_cookie.split(":");
var the_first = broken_cookies[0];
var the_name=the_first.split("=")[0];
var the_value = the_first.split("=")[1];
复杂的读取
// load the cookie into a variable and unescape it

var the_cookie = document.cookie;

var the_cookie = unescape(the_cookie);

// separate the values from the cookie name

var broken_cookie = the_cookie.split("=");

var the_values = broken_cookie[1];

// break each name:value pair into an array

var separated_values = the_values.split("/");

某个特定的cookie:
function WM_readCookie(name)
{

//如果没有cookie则返回false或者取得值并返回该值
if(document.cookie == '')
return false;
else
return
unescape(WM_getCookieValue(name));
}