Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Geek Culture / Need help creating different names for different cookies..

Author
Message
Mugen Wizardry
User Banned
Posted: 3rd Jun 2009 02:58
Hi all! I've been doing yet more research on cookies, and I have discovered 1 small flaw in my code..

What the problem would be is that whenever i have the same code for 2 different pages, i need to be able to have different cookie names. For example, if im on index.html , and i want to save that background to 1 cookie, named say for example "cookieimage1", then it will save the cookie. BUT if im on say another page like aboutus.html, and i want to save to a TOTALLY different cookie with the same name, like say "cookieimage2", then it will save the cookie TO ANOTHER NAME.

How would i create a function to return cookienamehere+x, where x = a number from 1 to infinite, or cookienamechangehere, where its a different name for each page entirely?

please note, u will need to create a folder named "images", and change the link(s) and the name(s) of the image(s) in the script whose variables are: backgroundImages, & backgroundNames... You will need an image called "MyImage.jpg", or whatever you changed it to.

here's the code:



ANY help is GREATLY appreciated!

Thanks!

~MW~
Jeku
Moderator
21
Years of Service
User Offline
Joined: 4th Jul 2003
Location: Vancouver, British Columbia, Canada
Posted: 3rd Jun 2009 04:21
Pardon me for obvious question, but you've created a lot of programming-related questions in the Geek Culture area. Wouldn't these be better suited to the Programmer forum?

Zdrok
18
Years of Service
User Offline
Joined: 19th Dec 2006
Location: Pittsburgh
Posted: 3rd Jun 2009 04:25
...and I thought you were talking about the food.

QuothTheRaven
22
Years of Service
User Offline
Joined: 2nd Oct 2002
Location: United States
Posted: 3rd Jun 2009 06:16
I can help with specific things only, so I'm going to ignore the entire block of code you posted. Ain't no way I'm bothering to read that.

The only question you asked:
Quote: "How would i create a function to return cookienamehere+x, where x = a number from 1 to infinite""

Use the super-common-super-useful cookie functions http://www.developertutorials.com/tutorials/javascript/custom-javascript-functions-060822/page9.html. You could do GetCookie in a while loop to check for cookiename+x and stop when it no longer returns something.

Login to post a reply

Server time is: 2025-06-02 09:40:25
Your offset time is: 2025-06-02 09:40:25