Basic Image Positioning

Discussion in 'Javascript' started by John Leeke, Oct 23, 2004.

  1. John Leeke

    John Leeke Guest

    How are images positioned on a page?

    In particular, how do I adapt the following javascript code:

    <img src="officecam0000.jpg" name="myImageName">
    <script language="JavaScript">
    function reloadImage() {
    var now = new Date();
    if (document.images) {
    document.images.myImageName.src = 'officecam0000.jpg?' +

    so that it positions and sizes the image the same as this html code:

    <p align="left"><img border="0" src="officecam0000.jpg" width="150"

    I am new to javascript, so you may have to spell it out for me.

    Thanks for your help.

    John Leeke, Oct 23, 2004
    1. Advertisements

  2. John Leeke

    Grant Wagner Guest

    They are positioned according to HTML layout standards... that is, an
    image appears inside inline elements inline and if placed in a block
    element will be separated from other block elements according to the
    default CSS of the specific HTML elements in a particular browser.

    So you can test:

    <!-- block test -->
    <div><img ...></div>

    <!-- inline test -->
    Drop this.
    This script does no "positioning" of the image, it simply attempts to
    guarantee (assuming client-side JavaScript) a fresh copy of the image
    gets loaded into the user agent approximately every 10 seconds.
    <script type="text/javascript">
    function reloadImage() {
    if (document.images) {
    document.images['myImageName'].src =
    'officecam0000.jpg?' + (+new Date());
    var t = setTimeout('reloadImage()', 10000);
    <body onload="setTimeout('reloadImage()', 10000);">
    <img name="myImageName"
    border="0" src="officecam0000.jpg"
    width="150" height="130">
    OfficeCam (10 second update)</p>
    Grant Wagner, Oct 25, 2004
    1. Advertisements

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.