Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

JavaScript Forum


You are currently viewing our JavaScript Forum as a guest. Please register to participate.
Login



Reply
How to make bgchange save color in cookies
Old 04-17-2012, 11:35 AM How to make bgchange save color in cookies
Junior Talker

Posts: 2
Trades: 0
HTML Code:
<div style="cursor: pointer; opacity: 1; position: fixed; right: 10px; top: 5px;">


<script type="text/**********">
function bgChange(bg)
{
document.body.style.background=bg;
}
</script>
<table border="1" height="20" style="width: 300px;"><tbody>
<tr> <td bgcolor="white" onclick="bgChange('')">
</td><td bgcolor="#699AB8" onclick="bgChange('#699AB8')">
</td><td bgcolor="#000000" onclick="bgChange('#000000')">
</td><td bgcolor="#FF00FF" onclick="bgChange('#FF00FF')">
</td><td bgcolor="#006400" onclick="bgChange('#006400')">
</td><td bgcolor="#FF6600" onclick="bgChange('#FF6600')">
</td><td bgcolor="#480082" onclick="bgChange('#480082')">
</td><td bgcolor="#dc143c" onclick="bgChange('#dc143c')">
</td><td bgcolor="#D4E3EA" onclick="bgChange('#D4E3EA')">
</td><td bgcolor="#B40404" onclick="bgChange('#B40404')">
</td><td bgcolor="#9A2EFE" onclick="bgChange('#9A2EFE')">
</td><td bgcolor="#236c95" onclick="bgChange('#236c95')">


</td></tr>
</tbody></table>
</div>
when i choose color .. background changes but when refresh it .. defaulte color come again ... it no save color i choosed

So , Can you edit these script to make it save color chooice in cookies ?
rexodia is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 04-17-2012, 07:39 PM Re: How to make bgchange save color in cookies
chrishirst's Avatar
Defies a Status

Posts: 43,949
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
http://www.w3schools.com/js/js_cookies.asp
__________________
Chris. ->>
Please login or register to view this content. Registration is FREE
<<-

A foolish consistency is the hobgoblin of little minds
Thought for today:- Is SEO the only industry where all the cowboys are Indians?
chrishirst is online now
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 04-18-2012, 09:06 AM Re: How to make bgchange save color in cookies
Junior Talker

Posts: 2
Trades: 0

i'm bad in js .. can you edit code and give me final code please .. as i tried make it my self but i failed
rexodia is offline
Reply With Quote
View Public Profile
 
Old 04-19-2012, 04:53 AM Re: How to make bgchange save color in cookies
miki86's Avatar
Extreme Talker

Posts: 239
Location: print_r($serbia);
Trades: 0
HTML Code:
<head>
<script type="text/javascript">
	function getCookie(c_name) {
		var i,x,y,ARRcookies=document.cookie.split(";");
		for (i=0;i<ARRcookies.length;i++) {
			x=ARRcookies[i].substr(0,ARRcookies[i].indexOf("="));
			y=ARRcookies[i].substr(ARRcookies[i].indexOf("=")+1);
			x=x.replace(/^\s+|\s+$/g,"");
			if (x==c_name) {
				return unescape(y);
			}
		}
	}
	
	function setCookie(c_name,value,exdays) {
		var exdate=new Date();
		exdate.setDate(exdate.getDate() + exdays);
		var c_value=escape(value) + ((exdays==null) ? "" : "; expires="+exdate.toUTCString());
		document.cookie=c_name + "=" + c_value;
	}
	
	function checkCookie() {
		var bgColor=getCookie("bgColor");
		if (bgColor!=null && bgColor!="") {
			document.body.style.background=bgColor;
		}
	}
	function bgChange(bg) {
		document.body.style.background=bg;
		setCookie('bgColor',bg,365000);
	}
</script>
</head>

<body onload="checkCookie()">
    <div style="cursor: pointer; opacity: 1; position: fixed; right: 10px; top: 5px;">
        <table border="1" height="20" style="width: 300px;"><tbody>
        <tr> <td bgcolor="white" onclick="bgChange('')">
        </td><td bgcolor="#699AB8" onclick="bgChange('#699AB8')">
        </td><td bgcolor="#000000" onclick="bgChange('#000000')">
        </td><td bgcolor="#FF00FF" onclick="bgChange('#FF00FF')">
        </td><td bgcolor="#006400" onclick="bgChange('#006400')">
        </td><td bgcolor="#FF6600" onclick="bgChange('#FF6600')">
        </td><td bgcolor="#480082" onclick="bgChange('#480082')">
        </td><td bgcolor="#dc143c" onclick="bgChange('#dc143c')">
        </td><td bgcolor="#D4E3EA" onclick="bgChange('#D4E3EA')">
        </td><td bgcolor="#B40404" onclick="bgChange('#B40404')">
        </td><td bgcolor="#9A2EFE" onclick="bgChange('#9A2EFE')">
        </td><td bgcolor="#236c95" onclick="bgChange('#236c95')">
        
        </td></tr>
        </tbody></table>
    </div>
</body>
This should be what you are looking for.
miki86 is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to How to make bgchange save color in cookies
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.38354 seconds with 11 queries