I am using ASP MVC 2.0 , i want to set Cookie from my Controller and read it from java Script i there any way to do so i have used following code in controller
HttpCookie ActiveTabs = new HttpCookie("tabs");
ActiveTabs.Values["top_navi_link"] = "ViewConference";
Response.Cookies.Add(ActiveTabs);
how to read it from java script.
I am using ASP MVC 2.0 , i want to set Cookie from my Controller and read it from java Script i there any way to do so i have used following code in controller
HttpCookie ActiveTabs = new HttpCookie("tabs");
ActiveTabs.Values["top_navi_link"] = "ViewConference";
Response.Cookies.Add(ActiveTabs);
how to read it from java script.
Share Improve this question edited Feb 13, 2012 at 13:32 Gaurav Mishra asked Feb 13, 2012 at 13:24 Gaurav MishraGaurav Mishra 711 silver badge5 bronze badges 4- 1 Use Google. w3schools./js/js_cookies.asp – CBusBus Commented Feb 13, 2012 at 13:26
-
3
@SOliver,
w3schools
? Seriously? There are also w3fools – Darin Dimitrov Commented Feb 13, 2012 at 13:30 - 1 @DarinDimitrov: Yes seriously; they provide a adequate solution to the OP's problem. w3fools are claiming that there is a lot of questionable content on the site, not that every item on it is wrong. – CBusBus Commented Feb 13, 2012 at 13:45
- I agree with SOliver here. Most of W3Schools is good info, but there are quite a few bad ones. And the bulk of the "bad ones" are very nitpicky. – Darthg8r Commented Feb 13, 2012 at 14:46
2 Answers
Reset to default 4Use this jquery jquery-cookies.js
which make it easy:
var cookiedata = $.cookie('top_navi_link');
<script type="text/javascript">
alert(document.cookie);
</script>
There are also some jquery plugins such as jquery.cookie which might simplify this task.