Insert embedded stylesheet as block?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Gnarlodious

    Insert embedded stylesheet as block?

    I'm hoping someone can explain this and give a tip what I'm doing wrong.

    This doesn't work (simplified for readability):

    <style type="text/css">
    <SCRIPT TYPE='text/javascript' LANGUAGE='JavaS cript'>
    if ( navigator.platf orm.substring(0 ,3).toLowerCase () == 'win')
    document.write( 'body { font-family: Arial} ')
    else document.write( 'body {font-family: Gadget } ')
    </SCRIPT>
    </style>

    But this does:

    <SCRIPT TYPE='text/javascript' LANGUAGE='JavaS cript'>
    if ( navigator.platf orm.substring(0 ,3).toLowerCase () == 'win')
    document.write( '<style type="text/css"> \n' +
    'body{ font-family: Arial} \n' +
    '</style>')
    else document.write( '<style type="text/css"> \n' +
    'body { font-family: Gadget } \n' +
    '</style>')
    </SCRIPT>

    I've tried to write style text common to both if/else's in the HTML but it
    won't work. Why is this? Does JS act differently inside the style tags?

    -- Gnarlie


  • Ivo

    #2
    Re: Insert embedded stylesheet as block?

    "Gnarlodiou s" wrote[color=blue]
    > This doesn't work (simplified for readability):
    >
    > <style type="text/css">
    > <SCRIPT TYPE='text/javascript' LANGUAGE='JavaS cript'>
    > if ( navigator.platf orm.substring(0 ,3).toLowerCase () == 'win')
    > document.write( 'body { font-family: Arial} ')
    > else document.write( 'body {font-family: Gadget } ')
    > </SCRIPT>
    > </style>
    >
    > But this does:[/color]

    <SCRIPT TYPE='text/javascript'>
    var font = ( navigator.platf orm.substring(0 ,3).toLowerCase () == 'win') ?
    'Arial' : 'Gadget';
    document.write(
    '<style type="text/css"> \n' +
    'body{ font-family: '+font+ ' } \n' +
    '</style>'
    );
    </SCRIPT>
    [color=blue]
    > I've tried to write style text common to both if/else's in the HTML but it
    > won't work. Why is this? Does JS act differently inside the style tags?[/color]

    JS does not act at all inside style tags. Inside style tags only style rules
    make sense. It is a pity that we cannot test directly for the presence of
    certain fonts on user's system, but why don't you simply write
    body{ font-family: Gadget, Arial, sans-serif; }
    so that the next is used if the first does not exist?
    HTH
    Ivo



    Comment

    • Gnarlodious

      #3
      Re: Insert embedded stylesheet as block?

      Entity Ivo spoke thus:
      [color=blue]
      > JS does not act at all inside style tags. Inside style tags only style rules
      > make sense. It is a pity that we cannot test directly for the presence of
      > certain fonts on user's system, but why don't you simply write
      > body{ font-family: Gadget, Arial, sans-serif; }[/color]

      I guess I'll do that. Thanks for verifying what I suspected.


      -- Gnarlie

      Spectrumology is the science of chaos.


      Comment

      Working...