Pooja
Pooja

Reputation: 11

Read cookie values through javascript or jquery

I have called one asp page inside the iframe

You can check here: https://www.fiestacups.com/ProductDetails.asp?ProductCode=DUMMY

If customer select font and select clip art image or upload image for clip art then I have store all that values in cookies.

Now I want to get that cookies values in java-script variable on the another page.

How can I do this? Please help me....

Upvotes: 1

Views: 4033

Answers (3)

Ved
Ved

Reputation: 8767

on another page you can use to read the value stored in cookie :-

var value = document.cookie("name_of_cookie");

Upvotes: 0

Roshan Wijesena
Roshan Wijesena

Reputation: 3136

function get_cookie ( cookie_name )
            {
                var results = document.cookie.match ( '(^|;) ?' + cookie_name + '=([^;]*)(;|$)' );

                if ( results )
                    return ( unescape ( results[2] ) );
                else
                    return null;
            }
            function set_cookie ( name, value, exp_y, exp_m, exp_d, path, domain, secure )
            {
                var cookie_string = name + "=" + escape ( value );

                if ( exp_y )
                {
                    var expires = new Date ( exp_y, exp_m, exp_d );
                    cookie_string += "; expires=" + expires.toGMTString();
                }

                if ( path )
                    cookie_string += "; path=" + escape ( path );

                if ( domain )
                    cookie_string += "; domain=" + escape ( domain );

                if ( secure )
                    cookie_string += "; secure";

                document.cookie = cookie_string;
            }
 set_cookie ( "iframeURL", "hello" );

var test=get_cookie ( "iframeURL" );

Upvotes: 0

Samich
Samich

Reputation: 30115

Using jquery cookies plugin is quiet simple:

// read 
$.cookie('whatever')

// write 
$.cookie('whatever', 'my whatever value')

Upvotes: 2

Related Questions