473,473 Members | 1,469 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

How to work with alternate stylesheet in a html page using cookies

30 New Member
Hello
I have a problem with how to use alternate stylesheet in my site home page using cookies.
Normal html file is working with out using cookies.But i have to give authority to customer to use their own stylesheet for showing the home page of my site .


If any one done this plz......................
Reply me.
Thanks.
Apr 17 '07 #1
5 1853
acoder
16,027 Recognized Expert Moderator MVP
Use name-value pairs as described on this page. You can use a save button to set the cookie and then on page load read the cookie and set the stylesheet.
Apr 17 '07 #2
snitu
30 New Member
Use name-value pairs as described on this page. You can use a save button to set the cookie and then on page load read the cookie and set the stylesheet.
Hi
I have a problem with using cookies.Can u give me proper example of alternate stylesheet using in a html page?

Thanks
Apr 18 '07 #3
acoder
16,027 Recognized Expert Moderator MVP
Hi
I have a problem with using cookies.Can u give me proper example of alternate stylesheet using in a html page?

Thanks
Well, if you've got it working without cookies, you just need to know how to use cookies and the rest should be easy. Use the functions in the link which makes it easy to create, read and delete cookies. Either use links or buttons to create them. Just store the name of the stylesheet.

Read through and try your hand at it. If you get stuck, post your code.
Apr 18 '07 #4
snitu
30 New Member
Well, if you've got it working without cookies, you just need to know how to use cookies and the rest should be easy. Use the functions in the link which makes it easy to create, read and delete cookies. Either use links or buttons to create them. Just store the name of the stylesheet.

Read through and try your hand at it. If you get stuck, post your code.

Hi

I am sending my code plz. check it and reply me.
/----------------------------------------------------------------------------------
[HTML]<html>
<head>
<title>css change</title>
<link rel="stylesheet" type="text/css" href="new.css" title="Red" />
<link rel="stylesheet" type="text/css" href="new1.css" title="Gray" />
<script type="text/javascript">
function setActivestylesheet(newStyle) {
var i, a, main;
for(i=0; (a = document.getElementsByTagName("link")[i]); i++)
{
if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title"))
{
a.disabled = true;
if(a.getAttribute("href") == newStyle)
{
a.disabled = false;
//Next section creates the cookie.
var days=365;
var name="Style";
var value=a.getAttribute("title");
if (days) {
var date = new Date();
date.setTime(date.getTime()+(days*24*60*60*1000));
var expires = ";
expires="+date.toGMTString();
}
else expires = "";
document.cookie = name+"="+value+expires+"; path=/new1.css";

}
}
}

}

window.onload = function(e) {
var cookie = readCookie("Style");
if (cookie == null) {
createCookie('Style', 'Red', '365');
}
return null;
}

function readCookie(name) {

var nameEQ = name + "=";
var temp = document.cookie;

var ca = document.cookie.split(';');
for(var i=0;i < ca.length;i++) {
var c = ca[i];
while (c.charAt(0)==' ') c = c.substring(1,c.length);



if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
}
return null;
}

function createCookie(name, value, days) {
if (days) {
var date = new Date();
date.setTime(date.getTime()+(days*24*60*60*1000));
var expires = "; expires="+date.toGMTString();
}
else expires = "";
var temp = name+"="+value+expires+"; path=/new1.css";
document.cookie = temp;

}
function setActiveStyleSheet(newStyle) {
var i, a, main;
for(i=0; (a = document.getElementsByTagName("link")[i]); i++)
{
if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title"))
{
a.disabled = true;
if(a.getAttribute("href") == newStyle)
{
a.disabled = false;
//Next section creates the cookie.
var days=365;
var name="Style";
var value=a.getAttribute("title");
if (days) {

var date = new Date();
date.setTime(date.getTime()+(days*24*60*60*1000));
var expires = ";
expires="+date.toGMTString();
}
else expires = "";
document.cookie = name+"="+value+expires+"; path=/new1.css";
//Above section creates the cookie

}
}
}

}

function getActiveStyleSheet() {
var i, a;
for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title") && !a.disabled) return a.getAttribute("title");
}
return title;
}

function getPreferredStyleSheet() {
var i, a;
for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
if(a.getAttribute("rel").indexOf("style") != -1
&& a.getAttribute("rel").indexOf("alt") == -1
&& a.getAttribute("title")
)
{
return a.getAttribute("title");
}
}
//return null;
}


window.unload = function(e) {
var title = getActiveStyleSheet();
createCookie("style", title, 365);

}



</script>
</head>
<body>
<a href="#" onclick="setActivestylesheet('new.css'); return false;">change style to default</a>

<a href="#" onclick="setActivestylesheet('new1.css'); return false;">change style </a>


<p class="aStyleClass1">Change Style</p>
</body>
</html>[/HTML]
/------------------------------------------------------------------------------------------------
Apr 21 '07 #5
acoder
16,027 Recognized Expert Moderator MVP
In your onload function, you need to set the stylesheet too. At the beginning, set only one stylesheet, not both. I prefer to use the id to refer to elements.
Apr 26 '07 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: vishal | last post by:
hi i am using session in php. but if the client has disabled his cookie then will my session work or not????????? thxs for your reply in advance.............
13
by: Toby A Inkster | last post by:
www.authoring.stylesheets] For ages I have provided links to alternate stylesheets from my pages as per W3C recommendations: <link rel="stylesheet" href="baz" type="text/css" title="Baz"...
21
by: Steel | last post by:
Hi at all, I have a very long html page with many photo. Therefore the best to print this page is to print the some page as PDF. Therefore I maked a PDF file like my page to print best. I'ld want...
19
by: deko | last post by:
Firefox will not take the following "font-weight:bold" directive in my stylesheet. Works fine in IE. #rightMenuText h5 { font-weight:bold; padding-bottom:0px; padding-top: 10px;...
5
by: User | last post by:
If I want to provide alternate stylesheets (eg red.css, green.css), is it better to put all the stuff that is common to both sheets in a separate css file (eg basic.css) and use @import at the top...
1
by: Eric Lindsay | last post by:
I am trying to understand the differences between and uses of persistent, default and alternate styles. I have read http://www.w3.org/TR/REC-html40/present/styles.html section 14.3.2 on...
6
by: scottyman | last post by:
I can't make this script work properly. I've gone as far as I can with it and the rest is out of my ability. I can do some html editing but I'm lost in the Java world. The script at the bottom of...
4
by: E | last post by:
I am having trouble with setTimeout working on a second call to the setTimeout function from a second page which is an html page. Here is the scenario. I have a web page and onload it calls a...
9
by: johkar | last post by:
I need some browser implementation clarification. In the below example, the alternate stylesheet could be invoked by user agents that support alternate stylesheets or by script. Are there any...
1
by: snitu | last post by:
Hello I have a problem with how to use alternate stylesheet in my site home page using cookies. Normal html file is working with out using cookies.But i have to give authority to customer to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.