Forum Moderators: open

Message Too Old, No Replies

Cookies and layers

         

webboy1

4:59 pm on Feb 21, 2003 (gmt 0)

10+ Year Member



I have a Javascript draggable menu.

Is there anyway i can save its last co-ordinates in a cookie?

Basically (or perhaps not so basically), i want to store the co-ordinates in a cookie, so that when the user cliks through to a new page, the draggable menu for that page loads in the same position as it was left on the previous page...............does this make sense?

Any ideas?

Webboy

BlobFisk

5:15 pm on Feb 21, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I would imagine that this can be done using JavaScript. When the user releases the mouse (having dragged the layer to the position they want), trigger a javascript function which gets the x and y position of the layer and writes them as a variable into a cookie.

On the next page, read these coordinates and use them to reposition the layer.

webboy1

11:34 am on Feb 24, 2003 (gmt 0)

10+ Year Member



That is sort of what i was thinking........but i do not know how to do it.

Can you, or anyone else help with how i would go about writing the code to do this?

Webboy

BlobFisk

12:17 pm on Feb 24, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



webboy1,

The best way would be for you to sit down and slog your way through it! That way you'll have a perfect understanding of what's happening and how to tailor changes to suit your needs!

The areas to look at would be:

  • Determining the new top and left value of the layer, after the user has dragged it to it's new position.
  • Writing these values to a cookie (ie creating a cookie)
  • Reading these values from a cookie (ie reading from a cookie)
  • Using these values to dynamically write the left and top coordinates of the layer.

You will find some nice snippets of code in the handy, generic javascript coding thread [webmasterworld.com], and there are plenty of online resources that will help you out - the best one being here!

webboy1

12:35 pm on Feb 24, 2003 (gmt 0)

10+ Year Member



Cheers BlobFisk,

Sitting down and slogging my way through it is how i usually learn things, unfortunatley this time i have a deadline of tomorrow.

I would still honestly rather slogg it out myself, thanks for the initial guide of what to look for though.......appreciated.

Webboy

RossWal

7:00 pm on Feb 24, 2003 (gmt 0)

10+ Year Member



Webboy,
This might be of some (though limited help). It sounds like you have a script that moves the layer (div) relative to the cursor position. That script probably does something like this:

>> Gets the X & Y offsets between the cursor and the layer coordinates.

>> Resets the x & Y coordinates of the layer as the cursor moves (layer.top & layer.left maybe?)

What you need to do is capture the layer coordinates into global javascript vars (meaning vars not declared inside a function) and at some point get them into a coookie. A google search will yield tons of samples for setting JS cookies. You might set the cookie in the body onUnload event.

Next in the body onLoad event for each page you want to read the cookie and reposition the layer by setting its left and top properties.

Hopefully this will point you towards some puddles to start slogging in ;)