JavaScript and CSS

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

    JavaScript and CSS

    Hey,

    How to do something like this:

    <head>
    <style>
    img { width: <script>blaat() ;</script>;}
    </style>
    <script>
    function blaat()
    {
    return 50%;
    }
    </script>
    </head>
    thnx, A.T.

    ps. I'm trying to make something to let the size of images depend on the
    resolution of the visitor





  • Lasse Reichstein Nielsen

    #2
    Re: JavaScript and CSS

    "Ang Talunin" <please.no.spam @no-reply.com> writes:
    [color=blue]
    > How to do something like this:[/color]
    [color=blue]
    > <style>
    > img { width: <script>blaat() ;</script>;}
    > </style>[/color]
    [color=blue]
    > <script>
    > function blaat()
    > {
    > return 50%;
    > }
    > </script>
    > </head>[/color]


    You can't embed scripts in style elements. The only solution is to
    write the entire style element:

    <script type="text/javascript">
    function blaat() {return "50%";}
    </script>
    ....
    <script type="text/javascript">
    document.write( "<style type=\"text/css\">");
    document.write( "img {width:" + blaat() + ";}");
    document.write( "<\/style>");
    </script>

    [color=blue]
    > ps. I'm trying to make something to let the size of images depend on the
    > resolution of the visitor[/color]

    Don't. You can make them depend on the size of the browser, but the
    resolution of the screen is completely irrelevant unless you happen to
    know the size of the screen as well. There is a world of difference
    between the same resolution on a 19" and a 14" monitor.

    /L
    --
    Lasse Reichstein Nielsen - lrn@hotpop.com
    Art D'HTML: <URL:http://www.infimum.dk/HTML/randomArtSplit. html>
    'Faith without judgement merely degrades the spirit divine.'

    Comment

    • Evertjan.

      #3
      Re: JavaScript and CSS

      Ang Talunin wrote on 07 okt 2003 in comp.lang.javas cript:[color=blue]
      > How to do something like this:
      >
      > <head>
      > <style>
      > img { width: <script>blaat() ;</script>;}
      > </style>
      > <script>
      > function blaat()
      > {
      > return 50%;
      >}
      > </script>
      > </head>[/color]

      <script>

      function blaat() {
      return "50%";
      // mind: a string!
      }

      var x = document.getEle mentsByTagName( "img")
      for(i=0; i<x.length; i++)
      x[i].style.width=bl aat()

      </script>

      not tested.

      --
      Evertjan.
      The Netherlands.
      (Please change the x'es to dots in my emailaddress)

      Comment

      Working...