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 Save CSS/StyleSheet in Database ?
Old 07-23-2009, 05:08 AM How to Save CSS/StyleSheet in Database ?
Junior Talker

Posts: 3
Name: Farhan Bajwa
Trades: 0
Hi,

Is there any way to store CSS settings and classes into a database. I have a css file describing styles for whole website.
I want to give user an option, to modify styles (background color, font, table header font, etc.) of thier own choices (at run-time). When user selects from the given options and hit save, then these values store in the database, so that when user visits the website next time then customized styles (theme) should be displayed on the web pages rather than default styles.
I know this can be done by using cookies (through javascript) but the problem arises when user visits the website after deleting private data of browser. In this way, again default styles applies to all web pages.

I am using javascript for dynamic changing of css files. Is there any way to get involved database in javascript to store css styles ?



Thanks,
Farhan.
FarhanBajwa is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 07-23-2009, 09:03 AM Re: How to Save CSS/StyleSheet in Database ?
Average Talker

Posts: 15
Trades: 0
You can make it variable, yes. Set your page to be parsed server-side (usually, you can do this by just changing the file extension.) You will have to set the HTTP header of this document to text/css. Then set some variables in the header of your page and use these throughout your document.

For example, in PHP, you'd do it like this:
PHP Code:
<?php
header
("Content-Type: text/css; charset=utf-8");
/* style variables */
if(!$_GET['header-background']) {
$header-background = "#39f";
}
if(!
$_GET['header-text']) {
$header-text = "#fff";
}
if(!
$_GET['body-background']) {
$body-background = "#fff";
}
if(!
$_GET['body-text']) {
$body-text = "#222";
}
?>
* {
margin: 0;
padding: 0;
border: 0;
}
#header {
background: <?php echo $header-background; ?>
color: <?php echo $header-text; ?>
}
#content {
background: <?php echo $body-background; ?>
color: <?php echo $body-text; ?>
}

You'd have to pass these on by using HTTP GET variables, which are visible. You attach them to the end of your URI, like so:
http://example.com/index.php?header-background=#3399ff&header-text=#ffffff
__________________

Please login or register to view this content. Registration is FREE
,
Please login or register to view this content. Registration is FREE
(web hosting at 50% off),
Please login or register to view this content. Registration is FREE

Please login or register to view this content. Registration is FREE
( free ads posting)
bholu is offline
Reply With Quote
View Public Profile
 
Old 07-23-2009, 09:28 AM Re: How to Save CSS/StyleSheet in Database ?
wayfarer07's Avatar
Poo on You

Latest Blog Post:
Introducing WowWindow
Posts: 3,985
Name: Abel Mohler
Location: Asheville, North Carolina USA
Trades: 0
FarhanBajwa,
JavaScript does not have any access to the server and can not talk to databases. It is purely client-side. If you want to send a message with JS you must use AJAX calls, then process the calls server side with a server programming language that has access to a database. This is why you were given a PHP answer.
__________________
Join me on
Please login or register to view this content. Registration is FREE
wayfarer07 is offline
Reply With Quote
View Public Profile Visit wayfarer07's homepage!
 
Reply     « Reply to How to Save CSS/StyleSheet in Database ?
 

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.43643 seconds with 12 queries