Michael C. Toren on 18 Nov 2007 20:10:34 -0000


[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]

Re: [PLUG] OT: javascript


On Sun, Nov 18, 2007 at 07:49:56PM +0000, Jeff Abrahamson wrote:
> > Googling and reading has gotten me this far:
> > 
> >     http://jeff.purple.com/foo.html
> 
> *Sigh*.  Never mind.  I got it.
> 
> Never fails: hack and read for an hour, don't get it, post, hit send,
> inspiration hits.

Rather than using document.write(), you can also modify the
attributes of an existing HTML element by doing something like:

    document.getElementById("resizeimage").innerHTML = "foo";

An example using that technique:

    <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
    <html>
    <head>
    <title>Javascript Image Resizing Hack</title>
    <script type="text/JavaScript">
    <!--
    function main()
    {
        winH = 0, winW = 0;
    
        // "if" block to query winH and winW taken from Jeff's example
        if (parseInt(navigator.appVersion) > 3)
        {
            if (navigator.appName == "Netscape")
            {
                winW = window.innerWidth;
                winH = window.innerHeight;
            }
            if (navigator.appName.indexOf("Microsoft") != -1)
            {
                winW = document.body.offsetWidth;
                winH = document.body.offsetHeight;
            }
    
        }
    
        winH -= 20, winW -= 20;  // prevent scrolling
    
        if (winH > 0 && winW > 0)
        {
            document.getElementById("resizeimage").innerHTML =
                "<img src='foo.jpg' width=" + winW + " height=" + winH + ">"
        }
    }
    //-->
    </script>
    </head>
    <body onLoad='main()'>
    
    <div id=resizeimage><img src='foo.jpg'></div>
    
    </body>
    </html>
___________________________________________________________________________
Philadelphia Linux Users Group         --        http://www.phillylinux.org
Announcements - http://lists.phillylinux.org/mailman/listinfo/plug-announce
General Discussion  --   http://lists.phillylinux.org/mailman/listinfo/plug