View Full Version : javascript probs
allison
08-15-2002, 01:13 AM
Hello all,
Can someone tell me how to write this line in netscape 4.7
Here is the line from internet explorer 6
<img src = "../images/pic10.jpg" name = "pic10" >
javascript code ===================================
document.images.pic10.alt = "Picture from summer vacation";
==============================================
I want to add an alt tag but through the use of a function
not hard coding it? Is this possible in Netscape 4.7?
bye all :)
A.
beetle
08-15-2002, 02:09 AM
Um. If I'm not mistaken, NS4.x uses document.layers in place of document.all
adios
08-15-2002, 02:16 AM
Can't write the 'alt' attribute dynamically in NS4+ - it's not exposed in the DOM. Best workaround would be to output the entire tag using an inline document.write(); whether this gets it or not depends when & how (and why!) you need to do it...
allison
08-15-2002, 02:06 PM
hi adios & beetle...
Thanks for your advice.
I am writing a page with a image slideshow.
I have one image on the page without an alt tag.
I then put a bunch of navigation buttons that let the user
view many pictures. The user can only see one pic at a time. Each pic will be loaded in that one img tag I have on my page.
The alt tag must be different for each pic therefore I thought that writing the alt dynamicly was the best solution. I guess it wasn't
:(
my code would be
javascript code ===================================
var imag = new Array();
imag[0] = "sum1.jpg";
imag[1] = "sum1.jpg";
imag[2] = "sum1.jpg";
==============================================
html code ----------------------------------------------
<img src = "../images/sum1.jpg" name = "pic1" >
----------------------------------------------------
javascript code ===================================
function swi() {
//code...
document.images.pic10.alt = "Picture from summer vacation"; //this would be changed to an array of alt messages
==============================================
I can only keep one img tag on my page so I don't know how I would be able to use document.write unless it can somehow erase my old img tag or just modify it. In ie this can be done with innerHtml but that also causes problems in nn4.7
anyway I will keep on trying and for now I will not have alt tags.
Thanks
A.
adios
08-15-2002, 07:21 PM
hey allison -
Don't give up so easily :( You could do it by re-writing the entire <img> tag (NS4) each time, inside a Layer.
<html>
<head>
<title>painful rectal itch</title>
<script type="text/javascript" language="javascript">
var pics = new Array;
pics.dir = 'http://www.dli.ch/hobbies/Cooking/'; //img directory
pics[0] = {
src: 'myfood-breakfest03f_small.jpg' ,
alt: 'Fruit'
}
pics[1] = {
src: 'vegetables00f_small.jpg' ,
alt: 'Some vegetables'
}
pics[2] = {
src: 'myfood-breakfast00f_small.jpg' ,
alt: 'My breakfast'
}
pics[3] = {
src: 'myfood09f_small.jpg' ,
alt: 'Bread'
}
pics[4] = {
src: 'david-horses00f_small.jpg' ,
alt: 'Horsemeat'
}
//preloader
var n = 0;
while (pics[n]) {
pics[n].obj = new Image();
pics[n].obj.src = pics.dir + pics[n++].src;
}
function newPic(fwd) {
if (typeof newPic.whichpic == 'undefined') newPic.whichpic = 0;
if (fwd)
newPic.whichpic = (newPic.whichpic == pics.length-1) ? 0 : ++newPic.whichpic;
else
newPic.whichpic = (newPic.whichpic == 0) ? pics.length-1 : --newPic.whichpic;
if (!document.layers) {
document.slide.src = pics.dir + pics[newPic.whichpic].src;
document.slide.alt = pics[newPic.whichpic].alt;
} else {
var pl = document.piclayer.document.layers[0];
var tag = '<img border="0" src="' + pics.dir + pics[newPic.whichpic].src + '" alt="' + pics[newPic.whichpic].alt + '">';
pl.visibility = 'hide';
pl.document.write(tag);
pl.document.close();
setTimeout('document.piclayer.document.layers[0].visibility="show"',50);
}
}
</script>
</head>
<body bgcolor="coral">
<div align="center"><br><br><br>
<table cellspacing="0" cellpadding="0" border="3" bgcolor="black">
<tr>
<td><ilayer id="piclayer"><layer><img name="slide" src="http://www.dli.ch/hobbies/Cooking/myfood-breakfest03f_small.jpg" alt="Fruit"></layer></ilayer></td>
</tr>
</table>
<a href="javascript:void newPic(true)">next</a>
<a href="javascript:void newPic()">prev</a>
</div>
</body>
</html>
Some old thingy I dug up.
cheers, adios
allison
08-16-2002, 02:33 AM
thanks adios :)
I'll see what I can do wityh that code
bye
A.
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.