vache
vache

Reputation: 341

retrieving saved url in cookie for body background jquery

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

Upvotes: 0

Views: 1019

Answers (2)

vache
vache

Reputation: 341

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>

Upvotes: 0

Shiva Srikanth Thummidi
Shiva Srikanth Thummidi

Reputation: 2908

 <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.

Upvotes: 2

Related Questions