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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.