Click here to Skip to main content
15,900,258 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
if I set cookie by 'loggedinUser'
JavaScript
document.cookie="loggedinUser=dawood"; 

then how to get this perticular 'loggedInUser' cookie value?
Posted

function getCookie(name)
  {
    var re = new RegExp(name + "=([^;]+)");
    var value = re.exec(document.cookie);
    return (value != null) ? unescape(value[1]) : null;
  }

More Info[^]
http://stackoverflow.com/questions/10730362/get-cookie-by-name[^]

-KR
 
Share this answer
 
v2
Comments
Dawood507 30-Sep-15 8:09am    
this is very difficult I cant understand.

I tried all liberary files which related to cookies

but cant apply in my page because this error throwing

$.cookie is not a function

so now I want to set and get cookie by using javascript

document.cookie("loggedinUser=dawood") if I set by this

then If I get cookie by document.cookie

then coming all cookies where as I want just 'loggedinUser' coockie value.

so simply how to get setted key value like

$.cookie("loggedInUser", username);
alert($.cookie("loggedInUser"));
C#
var x = getCookie('name');

                    function getCookie(name) {
                        var nameEQ = name + "=";
                        var ca = document.cookie.split(';');
                        for (var i = 0; i < ca.length; i++) {
                            var c = ca[i];
                            while (c.charAt(0) == ' ') c = c.substring(1, c.length);
                            if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length, c.length);
                        }
                        return null;
                    }

                    alert(x);
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900