用JS取得cookie中的参数
<?php
header(\'Content-Type: text/html;charset=utf-8\');
setcookie(\'cok\',"我是cookie",time()+360000);
?>
<script>
function $_COOKIE(sName){
var aCookie = document.cookie.split("; ");
for (var i=0; i < aCookie.length; i++){
var aCrumb = aCookie[i].split("=");
if (encodeURIComponent(sName) == aCrumb[0])
return decodeURIComponent(aCrumb[1]);
}
return null;
}
alert($_COOKIE(\'cok\'));
function GetUrlParam( paramName ){
var aCookie = document.cookie;
var oRegex = new RegExp(paramName + \'=([^;]+)\', \'i\' ) ;
//var oRegex = new RegExp( \'[\\?&]\' + paramName + \'=([^&]+)\', \'i\' ) ;
//var oMatch = oRegex.exec( window.top.location.search ) ;
//var oMatch = oRegex.exec( window.top.location.search ) ;
var oMatch = oRegex.exec( aCookie ) ;
if ( oMatch && oMatch.length > 1 )
return decodeURIComponent( oMatch[1] ) ;
else
return \'\' ;
}
这个函数大家应该很熟悉吧,fckeditor里面的。可谓经典呀。当然,也可以参看:取得URL中的参数
alert(GetUrlParam(\'cok\'));
</script>
header(\'Content-Type: text/html;charset=utf-8\');
setcookie(\'cok\',"我是cookie",time()+360000);
?>
<script>
function $_COOKIE(sName){
var aCookie = document.cookie.split("; ");
for (var i=0; i < aCookie.length; i++){
var aCrumb = aCookie[i].split("=");
if (encodeURIComponent(sName) == aCrumb[0])
return decodeURIComponent(aCrumb[1]);
}
return null;
}
alert($_COOKIE(\'cok\'));
function GetUrlParam( paramName ){
var aCookie = document.cookie;
var oRegex = new RegExp(paramName + \'=([^;]+)\', \'i\' ) ;
//var oRegex = new RegExp( \'[\\?&]\' + paramName + \'=([^&]+)\', \'i\' ) ;
//var oMatch = oRegex.exec( window.top.location.search ) ;
//var oMatch = oRegex.exec( window.top.location.search ) ;
var oMatch = oRegex.exec( aCookie ) ;
if ( oMatch && oMatch.length > 1 )
return decodeURIComponent( oMatch[1] ) ;
else
return \'\' ;
}
这个函数大家应该很熟悉吧,fckeditor里面的。可谓经典呀。当然,也可以参看:取得URL中的参数
alert(GetUrlParam(\'cok\'));
</script>