By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
437,712 Members | 2,174 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 437,712 IT Pros & Developers. It's quick & easy.

Help : Reading CSS through JavaScript

P: n/a
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
Share this Question
Share on Google+
3 Replies


P: n/a
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

P: n/a
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

P: n/a


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 discussion thread is closed

Replies have been disabled for this discussion.