views:

343

answers:

2

I am trying to retrieve a saved url from a jquery cookie its saving in the cookie but its not retrieving the cookie url

$(document).ready(function() { $("#BGSelector a").click(function() {
    var imgLink = $("img", this).attr("src");
        $.cookie("html_img", "" + imgLink + "", { expires: 7 });
        var imgCookieLink = $.cookie("html_img");
        $("html").css("background", "url('" + imgCookieLink + "')"); }); });

thanks to xandy for the jquery script

+2  A: 
 <script src="js/jquery.js" type="text/javascript"></script>
 <script src="js/jquery.cookie.js" type="text/javascript"></script>
 <script type="text/javascript" >
 $(document).ready(function() { 
    $("#BGSelector a").click(function() {
       var imgLink = $("img", this).attr("src");
       $.cookie("html_img", "" + imgLink + "", { expires: 7 });
       var imgCookieLink = $.cookie("html_img");
       $("html").css("background", "url('" + imgCookieLink + "')"); 
    }); 
 });
 </script>


<div id="BGSelector" >
<a href="javascript:;"><img src="images.jpeg" /></a>
</div>

This is working in my browser.once check your code.

Srikanth
what you mean .once
vache
ok than how can i make t so, it will retrieve this link after the user leaves and comes back, so it will be retrieving this link always when pages load
vache
A: 

this is funny all i did was call the cookie again

<script type="text/javascript">
$(document).ready(function() {   
   var imgCookieLink = $.cookie("html_img");  
   $("html").css("background", "url('" + imgCookieLink + "')"); 
 });

</script>
vache