Ok,
So I am creating a cookie using jquery and storing a div in it.
This div has a lot of formatting,other divs,text ,etc in it.
var rentContainer = document.createElement('div');
rentContainer.setAttribute("class","module");
var carContainer = document.createElement('div');
carContainer.setAttribute("class","carRentContainer");
rentContainer.appendChild(carContainer);
.... and a lot of other things go in this rentContainer div
Now save it in cookie
$.cookie('rented_car', rentContainer);
everythings looks ok upto now.
when the page is refreshed and the body is loaded, it is now time to get this div and show it on page ( with same formatting,structure, etc).
so in my function I have
var rented_car_cookie = $.cookie("rented_car");
if(rented_car_cookie){
document.getElementById('rentit').appendChild(rented_car_cookie);
//rentit is already defined and exists on the page. All I need is to add the cookie div content on it.
but this gives me an error message
Firebug’s log limit has been reached. 0 entries not shown. Preferences
uncaught exception: [Exception… “Could not convert JavaScript argument arg 0 [nsIDOMHTMLDivElement.appendChild]” nsresult: “0x80570009 (NS_ERROR_XPC_BAD_CONVERT_JS)” location: “JS frame :: iGo.js :: checkCookies :: line 10” data: no]
Please help. What is the best way to do this?
Anyway, storing full html element in cookie it bad thing. Maybe it’s better use JSON.
Anyway you can try to save
divas html string in the cookie.Code: http://jsfiddle.net/yecf8/
But you need to know that there are a lot of different limitations for different browsers regarding cookies. For example: