So I have a page with divs which I can drag. Is it possible - without JSON or database access to save positions of these divs so that when I open the page next time they are in the same place as I left them? This is a local file so I CAN write to the file - if that is at all a consideration.
Asked
Active
Viewed 274 times
1
-
1Is using cookies an option? Alternatively, what browser? More modern browsers support offline storage that can be used. – GregL Feb 21 '12 at 15:09
-
I am targeting any modern browsers / Chrome/Firefox/IE/Safari. Yes, it will be a local page so offline storage is an option! – antonpug Feb 21 '12 at 15:56
2 Answers
1
I suggest reading this question/answer to learn how to get the position of a div with JavaScript: Get the position of a div/span tag.
After that, simply use JavaScript to persist the data in a cookie. Here's a decent tutorial to get you started on that.

Community
- 1
- 1

James Hill
- 60,353
- 20
- 145
- 161
0
Have you tried using cookies to store the information. IT would allow a means to save the window properties, and not reach back server side.
SET COOKIE
function setCookie(c_name,value,exdays)
{
var exdate=new Date();
exdate.setDate(exdate.getDate() + exdays);
var c_value=escape(value) + ((exdays==null) ? "" : "; expires="+exdate.toUTCString());
document.cookie=c_name + "=" + c_value;
}
GET COOKIE
function getCookie(c_name)
{
var i,x,y,ARRcookies=document.cookie.split(";");
for (i=0;i<ARRcookies.length;i++)
{
x=ARRcookies[i].substr(0,ARRcookies[i].indexOf("="));
y=ARRcookies[i].substr(ARRcookies[i].indexOf("=")+1);
x=x.replace(/^\s+|\s+$/g,"");
if (x==c_name)
{
return unescape(y);
}
}
}
CHECK COOKIE
function checkCookie()
{
var username=getCookie("username");
if (username!=null && username!="")
{
alert("Welcome again " + username);
}
else
{
username=prompt("Please enter your name:","");
if (username!=null && username!="")
{
setCookie("username",username,365);
}
}
}

Jakub
- 20,418
- 8
- 65
- 92
-
2You should post your references when copying and pasting code from external sources. For example, this code comes from the site who's name shouldn't be spoken: http://www.w3schools.com/js/js_cookies.asp. See also: http://w3fools.com/ – James Hill Feb 21 '12 at 15:12
-
-