2

I want to add two products to comparison queue like on this site (http://www.phonearena.com/phones/manufacturers/Samsung) Here if you hover on a mobile phone and click on 'compare+' it add to a java-script or browser session and if you open another page and click on next any mobile 'compare+' button, it adds up to the comparison queue, which you can later use to compare two mobiles. I want to know what should I do, to achieve this functionality. My web app is being developed in MVC3 and I want to compare two of my products this way.

Please I just need some help how to figure this out. Thanks

6
  • 1
    Are cookies acceptable? If so, store your choice state in a session cookie for the site. Commented Sep 19, 2013 at 21:37
  • Or localStorage. Either would work. Commented Sep 19, 2013 at 21:38
  • @KirkB.: Yes cookies are acceptable. I just want to know whats the best way for this functionality. What do you suggest? Commented Sep 19, 2013 at 21:39
  • @MikeRobinson: HTML5 localStorage? or browser session? Commented Sep 19, 2013 at 21:40
  • HTML5... honestly it doesn't really matter than much what you use. @KirkB is suggesting the easiest, most reliable solution with cookies. All you really need to do is remember a list of product IDs. Commented Sep 19, 2013 at 21:43

2 Answers 2

2

Here is how you would use cookies:

document.cookie = "mobile1=" + mobile1;

and then you can retrieve it like so:

mobile1 = document.cookie
Sign up to request clarification or add additional context in comments.

6 Comments

I will surely try that.
This approach may work for you, but when you retrieve the cookie value, you're actually getting all cookies for your site with that call. Do you only plan to use one cookie for your site? If so, then fine. $.cookie plugin sorts those issues out for you.
@KirkB. can I retrieve cookies from a specific Path? I can erase the existing cookies at the time of onclick compare button call.
I suppose you can do both. Here is a similar issue with some worked out use of setting a cookie with a path: stackoverflow.com/questions/7487210/…
Here's an issue where they worked out being explicit with path using the jQuery cookie plugin: stackoverflow.com/questions/9326620/jquery-cookie-path
|
1

Give

http://plugins.jquery.com/cookie/

a try. Something like:

if ($.cookie("choices"))
{
    // have previous choice, so handle comparison display and reset state

    // ...

    $.removeCookie("choices");
}
else
{
    $.cookie("choices", "key of first product");
}

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.