Basic Image Positioning

J

John Leeke

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?' +
now.getTime();
}
setTimeout('reloadImage()',10000);
}
setTimeout('reloadImage()',10000);
</script>
**********

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"
height="130"><br>
OfficeCam(10sec.update)</p>
**********

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

Thanks for your help.

John
 
G

Grant Wagner

John said:
How are images positioned on a page?

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 -->
Test
<div><img ...></div>
Test

<!-- inline test -->
Test
In particular, how do I adapt the following javascript code:

**********
<img src="officecam0000.jpg" name="myImageName">

Drop this.
<script language="JavaScript">

function reloadImage() {
var now = new Date();
if (document.images) {
document.images.myImageName.src = 'officecam0000.jpg?' +
now.getTime();
}
setTimeout('reloadImage()',10000);
}
setTimeout('reloadImage()',10000);

Move this to said:
</script>

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.
**********

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"
height="130"><br>
OfficeCam(10sec.update)</p>
**********

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

<head>
<title>...</title>
<script type="text/javascript">
function reloadImage() {
if (document.images) {
document.images['myImageName'].src =
'officecam0000.jpg?' + (+new Date());
}
var t = setTimeout('reloadImage()', 10000);
}
</script>
</head>
<body onload="setTimeout('reloadImage()', 10000);">
<img name="myImageName"
border="0" src="officecam0000.jpg"
width="150" height="130">
<br>
OfficeCam (10 second update)</p>
</body>
 

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. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,756
Messages
2,569,535
Members
45,008
Latest member
obedient dusk

Latest Threads

Top