Use JavaScript to get the value of cookies

xiaoxiao2021-03-06  17

/ *******************************************************************

'** Function Name: Value of cookies

'** function function: display paging information

'** Parameter Description:

'** Strname to take the value of the cookies name

'** STRSUBNAME child name (if any)

'** function returns:

'** NULL said no value

'** cookies value returns (worth)

'** Reference Example:

'** var strcookie = getcookie ("MyCookies", "MySubCookies");

********************************************************* /

Function getCookie (Strname, strsubname)

{

Var strcookies = document.cookie.split (";");

Var IntCookiesLength = strcookies.length;

Var intlength;

Var stritem, strhead, strcookie;

For (var i = 0; i

{

// There will be & symbols when there is a child

IF (strcookies [i] .indexof ("&"))

{

// getting the head

Strhead = strcookies [i] .split ("=");

/ / Judgment whether or not the parameter to look

IF (strname == strhead [0])

{

// go to the head information

Strcookies [i] = strcookies [i] .substr (Strname.length 1);

// With & Segment character to get all children

Strcookie = strcookies [i] .split ("&");

Intlength = strcookie.length;

FOR (var j = 0; j

{

Stritem = strcookie [j] .split ("=");

IF (strsubname == stritem [0])

Return Unescape (Stritem [1]);

}

}

}

/ / Direct judgment of the value when there is no child

Else

{

Stritem = strcookies [i] .split ("=");

IF (strname == stritem [0])

Return Unescape (Stritem [1]);

}

}

Return NULL;

}

转载请注明原文地址:https://www.9cbs.com/read-56108.html

New Post(0)