Home > Web Front-end > JS Tutorial > Implementation method of obtaining specified cook information in js

Implementation method of obtaining specified cook information in js

高洛峰
Release: 2016-12-06 14:00:10
Original
1400 people have browsed it

Premise:

Getting cook in js is the most painful thing, because it does not save the value of the cook variable one by one, but all the variables exist together, and you can only get a certain cook by taking out the fields one by one. value.

So write a function to get the value of a certain variable:

function get_cookie(name)
    {
        var bikky = document.cookie;
        name += "=";
        var i = 0;
        while (i < bikky.length)
        {
            var offset = i + name.length;
            if (bikky.substring(i, offset) == name)
            {
                var endstr = bikky.indexOf(";", offset);
                if (endstr == -1) endstr = bikky.length;
                return unescape(bikky.substring(offset, endstr));
            }
            i = bikky.indexOf(" ", i) + 1;
            if (i == 0) break;
        }
        return null;
    }
Copy after login

Got it, tested it myself, and it’s usable.


Related labels:
js
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Issues
Where is js written?
From 1970-01-01 08:00:00
0
0
0
js file code not found
From 1970-01-01 08:00:00
0
0
0
js addClass not working
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template