Jump to content

How to set or create cookies for specific function in a page.


iconicCreator

Recommended Posts

I'm totally new to Javascript and really knows nothing.

I have manage to create a Javascript style switcher with the help of many good people on this and other forum.

 

This script causes the style sheets attached to my web page to change based on the user selection. When the user click a link or tab, the page changes styles.

 

There are two style sheets, default and zoom.

 

This is the function that process the style switching.

 

var mystylesheets=["default", "zoom"] 
var cursheet=1 
function rotateStyle(){ 
        chooseStyle(mystylesheets[cursheet], 60) 
        cursheet=(cursheet<mystylesheets.length-1)? cursheet+1 : 0 
        var obj = document.getElementById('mylink'); 
        if(obj.innerHTML == 'default') 
            obj.innerHTML = 'zoom'; 
        else 
            obj.innerHTML = 'default'; 
            
    } 

 

Here is the link the user can click to switch style sheets.

 

<a id="mylink" href="javascript:rotateStyle();">default</a>

 

When this link is click, the style sheet changes.

 

What this code also does is change the text or label on the link when the user click on it.

 

So when the user click on the tab/link - the text changes to zoom or default. This helps the user know what style sheet they have selected.

 

 

The problem is this.

 

I need a way to make the text or label stay on the tab/link even when the page is refreshed. Because when the page is refreshed, the label/text changes to default, even if the user is viewing in the zoom mode.

 

I need to know how I can set cookies for this.

 

I have searched Google but found nothing I can understand.

 

How do I set cookies so that the label stay on the tab even when the page is refreshed.

 

Any help will be greatly appreciated.

 

Thanks everyone.

 

IC

Here is info on reading/writing cookies with JavaScript:

http://www.w3schools.com/JS/js_cookies.asp

 

I'm just confused because I'm not trying to set cookies for a user name, it appears everything I read regarding cookies talks about getting user information for displaying.

 

I just want the page to remember the text on the label so that it can remain when the page is refreshed.

 

Thanks for the responds.

 

IC

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.