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
1337 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
source:php.cn
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template