Help : Reading CSS through JavaScript

Discussion in 'Javascript' started by Joop, Sep 28, 2005.

  1. Joop

    Joop Guest

    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.selectorText + ' {';

    for(var item in ssRules.style) {
    if(isIE && ssRules.style.getAttribute(item)) {
    output += '\n ' + item + ':';
    output += ssRules.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... :)
     
    Joop, Sep 28, 2005
    #1
    1. Advertising

  2. Joop

    RobG Guest

    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
     
    RobG, Sep 29, 2005
    #2
    1. Advertising

  3. Joop

    Joop Wiersma Guest

    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.selectorText + ' {';
    for(var item in ssRules.style) {
    if(isIE && ssRules.style.getAttribute(item)) {
    output += '\n ' + item + ':';
    output += ssRules.style.getAttribute(item) + ';';
    }
    }
    output += '\n}\n\n';
    }
    } else if (isNS) {
    for(i = 0; i < ssRules.length; i++) {
    output += ssRules.selectorText + '{';
    output += ' ' + ssRules.style.cssText + '\n';
    output += '}\n\n';
    }
    }
    alert(output);
    }


    Again, Rob : "Thanks!" :)

    *** Sent via Developersdex http://www.developersdex.com ***
     
    Joop Wiersma, Sep 29, 2005
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Julie Siebel
    Replies:
    4
    Views:
    140
    Dr John Stockton
    Feb 25, 2004
  2. awoodgate
    Replies:
    2
    Views:
    78
    awoodgate
    Dec 10, 2005
  3. Replies:
    7
    Views:
    200
  4. Jay

    reading DOM through javascript

    Jay, Nov 16, 2007, in forum: Javascript
    Replies:
    4
    Views:
    123
  5. Sura
    Replies:
    3
    Views:
    663
    -TNO-
    Aug 14, 2009
Loading...

Share This Page