Function Set_Cookie
Enviado por ftytyty • 14 de Febrero de 2013 • 270 Palabras (2 Páginas) • 302 Visitas
<!doctype html><html><head><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta http-equiv="content-type" content="text/html; charset=UTF-8">
<script type="text/javascript">
function getParam(name,s)
{
name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
var regexS = "[\\?&]"+name+"=([^&#]*)";
var regex = new RegExp( regexS );
var results = regex.exec( s?s:window.location.href );
if( results == null )
return "";
else
return unescape(results[1]);
}
function Set_Cookie( name, value, expires, path, domain, secure )
{
var today = new Date();
today.setTime(today.getTime());
if (expires)
expires = expires * 1000 * 60 * 60 * 24;
var expires_date = new Date(today.getTime() + (expires));
document.cookie = name + "=" +escape(value) +
( (expires) ? ";expires=" + expires_date.toGMTString() : "" ) +
( (path) ? ";path=" + path : ";path=/" ) +
( (domain) ? ";domain=" + domain : ";domain=."+document.location.hostname ) +
( (secure) ? ";secure" : "" );
}
function Get_Cookie( name )
{
var start = document.cookie.indexOf( name + "=" );
var len = start + name.length + 1;
if ( (!start) &&
(name != document.cookie.substring(0, name.length)) )
return null;
if ( start == -1 )
return null;
var end = document.cookie.indexOf( ";", len );
if ( end == -1 )
end = document.cookie.length;
return unescape( document.cookie.substring(len, end) );
}
function hasLocalStorage()
{
var r = false;
try{
r = window.localStorage ? true: false;
}catch(e){}
return r;
}
function hasPostMessage()
{
return window.postMessage && navigator.userAgent.indexOf('Opera')==-1;
}
function handler(e)
{
if (typeof(e.data)!="string")
return;
if (e.data.indexOf("get ")==0)
{
var name = e.data.substring(4);
var value;
if (hasLocalStorage())
{
value = localStorage[name];
if (value==null)
{
value = Get_Cookie(name);
if (value!=null)
localStorage[name] = value;
}
else
{
if (name=="aid")
{
var valuetest = Get_Cookie(name);
...