2

I am using ASP.net 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.

4
  • 1
    Use Google. w3schools.com/js/js_cookies.asp Commented Feb 13, 2012 at 13:26
  • 3
    @SOliver, w3schools? Seriously? There are also w3fools 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. 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. Commented Feb 13, 2012 at 14:46

2 Answers 2

4

Use this jquery jquery-cookies.js which make it easy:

var cookiedata = $.cookie('top_navi_link');
Sign up to request clarification or add additional context in comments.

Comments

3
<script type="text/javascript">
    alert(document.cookie);
</script>

There are also some jquery plugins such as jquery.cookie which might simplify this task.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.