473,385 Members | 1,720 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Help : Reading CSS through JavaScript

Hello everybody,

I'm trying to build a page that can be manipulated by any user through
CSS. The user can then store his layout in a database, so it can be
presented on the web. Therefore I'm trying to build a function that
will output the complete CSS to a database.

Here's my code:

var isIE = (navigator.appName == "Microsoft Internet Explorer");
var isNS = (navigator.appName == "Netscape");

// Genereert output voor opslag in database
function generateCSS() {
var output = '';

var sheet = parent.app.document.styleSheets[0];
var ssRules = sheet.cssRules || sheet.rules;

for(i = 0; i < ssRules.length; i++) {

output += ssRules[i].selectorText + ' {';

for(var item in ssRules[i].style) {
if(isIE && ssRules[i].style.getAttribute(item)) {
output += '\n ' + item + ':';
output += ssRules[i].style.getAttribute(item) + ';';
} else if (isNS) {
output += 'what the hell shoud I put here!?';
}
}
output += '\n}\n\n';
}
alert(output);
}

Though this works pretty cool in IExplorer, I can't seem to get this
working with Mozilla. Can anyone help me on this one?!? I've been
studying these forums for hours now, and can't seem to come up with a
decent working solution.

Thnx in advance for any kind of attention to this... :-)

Sep 28 '05 #1
3 2108
Joop wrote:
Hello everybody,

I'm trying to build a page that can be manipulated by any user through
CSS. The user can then store his layout in a database, so it can be
presented on the web. Therefore I'm trying to build a function that
will output the complete CSS to a database.

Here's my code:
[...]
Though this works pretty cool in IExplorer, I can't seem to get this
working with Mozilla. Can anyone help me on this one?!? I've been
studying these forums for hours now, and can't seem to come up with a
decent working solution.


What on earth would we do without quirksmode?

<URL:http://www.quirksmode.org/dom/w3c_css.html>

--
Rob
Sep 29 '05 #2
Rob,

Thanks a million! That was a MAJOR help, and I've been able to finish my
code now...
(Perhaps I'll be "finetuning" it a little bit in the future, now that I
have all thie "new knowledge", but hey... It works!)

In case anyone's interested, here's what I finally did :

function generateCSS() {
var output = '';
var i;
var sheet = parent.app.document.styleSheets[0];
var ssRules = sheet.cssRules || sheet.rules;

if(isIE) {
for(i = 0; i < ssRules.length; i++) {
output += ssRules[i].selectorText + ' {';
for(var item in ssRules[i].style) {
if(isIE && ssRules[i].style.getAttribute(item)) {
output += '\n ' + item + ':';
output += ssRules[i].style.getAttribute(item) + ';';
}
}
output += '\n}\n\n';
}
} else if (isNS) {
for(i = 0; i < ssRules.length; i++) {
output += ssRules[i].selectorText + '{';
output += ' ' + ssRules[i].style.cssText + '\n';
output += '}\n\n';
}
}
alert(output);
}
Again, Rob : "Thanks!" :-)

*** Sent via Developersdex http://www.developersdex.com ***
Sep 29 '05 #3


Joop wrote:
Hello everybody,

I'm trying to build a page that can be manipulated by any user through
CSS. The user can then store his layout in a database, so it can be
presented on the web. Therefore I'm trying to build a function that
will output the complete CSS to a database. <snip> Though this works pretty cool in IExplorer, I can't seem to get this
working with Mozilla. Can anyone help me on this one?!? I've been
studying these forums for hours now, and can't seem to come up with a
decent working solution.

Thnx in advance for any kind of attention to this... :-)

Heres a little piece that might have some usefull bits in it.
http://www.drclue.net/projects/jsDHT.../OperaCSS.html

This one works with IE,Opera, and Firefox.

It actaully reads and parses the CSS file directly , which allows
it to work in even Opera , which has no direct access to it's stylesheets.

It allows you to pick stylesheets and load them on demand,
and can even load stylesheets from other domains.

It's jut a piece in a larger project I'm working on.

--
--.
--=<> Dr. Clue (A.K.A. Ian A. Storms) <>=-- C++,HTML, CSS,Javascript
--=<> Internet Programming since 1994 <>=-- DHTML NSAPI TCP/IP
--=<> http://resume.drclue.net <>=-- AJAX, SOAP, XML, HTTP
--=<> http://www.drclue.net <>=-- SERVLETS,TCP/IP, SQL
--.
Oct 1 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

17
by: Sue | last post by:
<html> Is there someone here that can help me validate the period as the fourth from the last character in an email address. There is other information and validation on the form I have to do but...
14
by: enrique | last post by:
I'm trying to debug my expression that matches an alphanumeric with any number of dashes (including none), except at the ends and obviously disallowing two or more consecutive dashes. Here it...
25
by: Dave Turner | last post by:
I know that its impossible to completely prevent somebody from ripping a site (or cracking software) if that person has the skills and the time/patience, but there are tricks that can be employed...
10
by: Bishoy George | last post by:
// I wrote the following code but it is not working. // Any help please? // ------------------------------------------------ using System; using System.Collections; using System.ComponentModel;...
5
by: Dennis Fazekas | last post by:
Greetings, I am creating a web form which will all the user to add an unlimited number of email addresses. Basically I have 3 buttons, "Add Another Email", "-" to remove, and a "Save" button....
9
by: Mike Reed | last post by:
I must be having a "senile" day! I cannot recall, nor get to work, code to read a cookie's expiration date/time in an ASP page/VBScript. What am I missing? *** Sent via Developersdex...
1
by: Nestor | last post by:
Hello all, I'm begining in the web services world and I've reading about how to invoke them using javascript from Mozilla browser (version 2.0 in my case). I found a very interesting example...
0
by: gunimpi | last post by:
http://www.vbforums.com/showthread.php?p=2745431#post2745431 ******************************************************** VB6 OR VBA & Webbrowser DOM Tiny $50 Mini Project Programmer help wanted...
29
by: Barry | last post by:
I know this is not a php question. If that bothers you, don't respond. If not, I sure could use the advice... I'm using a very abbreviated set of code to show a calendar. The idea is to simply...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have 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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.