[Javascript] How to separate the href + V8 moment
Triche Osborne
wdlists at triche-osborne.com
Thu Aug 11 10:51:14 CDT 2005
Scott Moore wrote:
> Triche, thanks so much for your help.
>
> The reason I wanted to pull the image name out of the onclick function
> is so that those who have JavaScript turned off would still be able to
> view the large version of the image.
>
> I thought it might be as easy as changing
> document.getElementById('placeholder').src = whichpic;
> to
> document.getElementById('placeholder').src = whichpic.href;
>
As you've seen, the problem isn't that this doesn't work from a JS
perspective, it's that the XHTML behavior negates it.
> However, that's not the case and the image href acts like a normal link.
>
> Any suggestions?
>
The simplest solution I can think of is to use JavaScript to write out
your anchors and images, then use NOSCRIPT tags to enclose the
alternative content. If you have a lot of thumbnails you can use a loop
structure to write them out. (If you're unsure how to do this, let me
know and I'll help.)
Also, as I was munching my breakfast, I had a "V8 moment" and realized
that I'd made the "selected" stuff more verbose than necessary. You
still need to create the ID for the first anchor, but the script can be
shortened to this:
var Ary=new Array();
var firstSelected;
window.onload = function() {
firstSelected = document.getElementById('first');
firstSelected.className = "selected";
Ary[0] = firstSelected;
}
function showPic (obj,whichpic) {
if (!obj.set){
obj.set=true;
Ary[Ary.length]=obj;
}
for (i=0;i<Ary.length;i++){
Ary[i].className='notselected';
}
obj.className='selected';
if (document.getElementById) {
document.getElementById('placeholder').src = whichpic;
}
}
This version initializes the checking array with the first object
(anchor) which eliminates the first if().
Triche
More information about the Javascript
mailing list