Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   Javascript (http://www.velocityreviews.com/forums/f68-javascript.html)
-   -   Help : Reading CSS through JavaScript (http://www.velocityreviews.com/forums/t920435-help-reading-css-through-javascript.html)

Joop 09-28-2005 03:23 PM

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... :-)


RobG 09-29-2005 12:53 AM

Re: Help : Reading CSS through JavaScript
 
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

Joop Wiersma 09-29-2005 06:55 AM

Re: Help : Reading CSS through JavaScript
 
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 ***


All times are GMT. The time now is 03:51 PM.

Powered by vBulletin®. Copyright ©2000 - 2013, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57