Forum Moderators: open

Message Too Old, No Replies

How to make browser remember Javascript from last page?

Is there a way I can change this code?

         

shrill

12:34 am on Jan 23, 2004 (gmt 0)

10+ Year Member



Hello everyone.

I am working on a page with a script from Dynamic Drive called the "Contractible Headers" script. You can see the script here:
[dynamicdrive.com...] . I am using images instead of text, and you can see my implementation here:
<Sorry, no URLs. See TOS [webmasterworld.com]>

I have been asked by my client if there is a way that the next page can "remember" what happened on the last page: ie. if the person opens the Job Seekers menu and goes to another page, the browser would present the menu already open.

As a relative newcomer to JavaScript, I really have no idea if this is possible. I'm tempted to set up an external Javascript file: would that do it?

Thanks so much,

Cheryl

[edited by: tedster at 4:36 pm (utc) on Jan. 23, 2004]

DrDoc

5:18 am on Jan 23, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Since the Web is stateless, you'd need to store the information somehow, in a cookie for example. Making the JS external does not help. The values are local to the current page.

shrill

2:33 pm on Jan 23, 2004 (gmt 0)

10+ Year Member



Of course: I hadn't even thought of this! I've never actually created a cookie myself before. Any hints on good URL's instructions? Or maybe even some code....? :)

Thanks: that is very helpful!

Cheers,

Cheryl

DrDoc

4:22 pm on Jan 23, 2004 (gmt 0)

shrill

4:42 pm on Jan 23, 2004 (gmt 0)

10+ Year Member



Thank you!

Okay, I've been reading a few of these threads: maybe you can tell me if I'm on the right track with what I think I need to accomplish.

The cookie needs to be created when the user clicks on the "job seekers" button: I can do this using the onClick method? Then, I need to write something that has the browser search for the cookie when the page loads and if it exists, present the script as activated already?

Am I headed in the right direction?

Best regards,

Cheryl

DrDoc

4:48 pm on Jan 23, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



That sounds right on the spot to me :)

shrill

6:18 pm on Jan 23, 2004 (gmt 0)

10+ Year Member



Good. Glad to hear it :)

Now, sorry to keep quizzing you but, here's my first road block: I can't figure out how to have 2 events onClick. Here is the two things I need to have happen:

The cookie (which I am hoping is formatted right):

<img onClick='setCookie("name", "save menu")'>

What is there already (the menu expansion):

<img onClick="expandcontent('sc1')" style="cursor:pointer; cursor:pointer" onMouseOver="MM_nbGroup('over','jobseekers','../graphics/jobseekersbuttondown.gif','',1)" onMouseOut="MM_nbGroup('out')" name="jobseekers" src="../graphics/jobseekersbuttonup.gif" border="0" onLoad="" width="132" height="22">

Would this be correct or is there a better way to do this? I'm really not sure about proper format/ order etc. or if it is even possible to have 2 events happen on one click.

<img onClick="expandcontent('sc1')" style="cursor:pointer; cursor:pointer" 'setCookie("name", "savemenustate")' onMouseOver="MM_nbGroup('over','jobseekers','../graphics/jobseekersbuttondown.gif','',1)" onMouseOut="MM_nbGroup('out')" name="jobseekers" src="../graphics/jobseekersbuttonup.gif" border="0" onLoad="" width="132" height="22">

DrDoc

6:41 pm on Jan 23, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You're on the right path! Something like this would probably work best:

<img onclick="setCookie("name", "savemenustate");expandcontent('sc1');" ... >

brucec

8:55 pm on Jan 23, 2004 (gmt 0)

10+ Year Member



I use cookies and they work pretty well

shrill

9:48 pm on Jan 23, 2004 (gmt 0)

10+ Year Member



Hi again DrDoc.

Okay, I tried this method and as far as I can tell, it has created a cookie. However, Dreamweaver (I'm using 4.0) really doesn't like it: marks it invalid (for a "duplicate attribute") and severely messes up the display in Dreamweaver (although it displays fine in IE).

Any thoughts?

Cheryl

shrill

9:50 pm on Jan 23, 2004 (gmt 0)

10+ Year Member



Never mind,I think I just fixed it (changed double quotes to single quotes in the cookie).

Cheryl

shrill

9:52 pm on Jan 23, 2004 (gmt 0)

10+ Year Member



Hi Brucec. Do you use a cookie for the same purpose?

Cheryl

Jeeek

12:10 pm on Jan 26, 2004 (gmt 0)

10+ Year Member



another thing you could think of (besides the cookie) is frames;

you could place your JavaScript in one frame which isn't reloaded (e.g. main navigation) - I think it even works when you place the script in the frameset itself; then just access it with parent.FrameName.function(); or parent.function();

but just do so if you already use a framset - don't make a framesite just because of that thingy.

just a thought..