JavaScript: set max width

    <script type="text/javascript">
    window.onload = resize;
    window.onresize = resize;

    function resize() {
    var max_width = 800

    /* - FireFox does not support object reference, must use getElementby */
    var doc_body = document.getElementsByTagName('body')[0];
    var doc_container = document.getElementById('container');


    /* - set the max width */
    /* - FireFox must have unit (px) */
    if (doc_body.clientWidth < max_width)
    doc_container.style.width = doc_body.clientWidth + 'px';
    else
    doc_container.style.width = max_width + 'px';

    }
    </script>
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s