473,378 Members | 1,578 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

JavaScript IE Compatibility Issue

I might as well start off like everyone else who posts problems they
are having....So I'm new to JavaScript.....

Anywho, I have a page that lists 15 or so thumbnails and then one big
image of one of those thumbnails. I wrote some javascript code that
when you click on the thumbnail the real picture of that thumbnail
loads in the big image on the page. So essentially I wrote some very
simple code that replaces the "src" of an image tag on an onClick
event. I also replace some text within some elements that are tagged
with an ID. Everything works great in all browsers except in internet
explorer 6.0 (and possibly other versions of IE, just 6.0 is all I'm
using). If anyone has run into this problem before, or notices
something wrong with the code, any insight would be GREAT. Thanks
All,
/*******************JAVA SCRIPT FUNCTION***********************/

<script type="text/javascript">
function click(name, title, susser, photographer, location)
{
fool = "http://www.gnarwire.com/photos/guest/" + name;
document.photo.src = fool;
document.getElementById('picTitle').innerHTML= title + " in " +
location;
document.getElementById('picSusser').innerHTML= susser;
document.getElementById('picPhotographer').innerHT ML= photographer;

}
</script>

/****************THUMBNAIL SECTION*********************/

<a class="thumbnail">
<img src="photos/guest/th256347_2Aguille du Midi 034.jpg"
onclick="click('256347_2Aguille du Midi 034.jpg', 'Crevasse Rescue
Training', 'Topher Plimpton', 'Mike Schirf', 'Mer de Glace');"
border="0" width="70px" height="70px">
</a>
<a class="thumbnail">
<img src="photos/guest/th256346_poubell 003.jpg"
onclick="click('256346_poubell 003.jpg', 'Harny Suss\'n Le Poubelle',
'Johannes Schmid', 'Mike Schirf', 'Chamonix');" border="0"
width="70px" height="70px">
</a>
<a class="thumbnail">
<img src="photos/guest/th256345_MattToph.jpg"
onclick="click('256345_MattToph.jpg', 'Mt. Blanc', 'Topher and Matt',
'Mike Schirf', 'Mt. Buet -- Chamonix');" border="0" width="70px"
height="70px">
</a>

/*********************BIG IMAGE SECTION********************/
<div class="post" id="post-1">
<H2 id="picTitle">
Crevasse Rescue Training in Mer de Glace
</H2>
<div class="entry">
<img src="photos/guest/256347_2Aguille du Midi 034.jpg" name="photo">
</div>
<div class="postmetadata">
<h3 align="center">
<spanSusser: </span>
<span id="picSusser">Topher Plimpton</span>
&nbsp &nbsp
<spanPhotographer:<span>
<span id="picPhotographer">Mike Schirf</span</h3>
</div>
</div>

Mar 31 '07 #1
2 6179
Lee
mr*******@gmail.com said:
>
Everything works great in all browsers except in internet
explorer 6.0 (and possibly other versions of IE, just 6.0 is all I'm
using).
/*******************JAVA SCRIPT FUNCTION***********************/

<script type="text/javascript">
function click(name, title, susser, photographer, location)
Change the name of your function. IE assigns a method named
"click" and silently ignores the one you create. You'll find
that some people think IE is lousy software.
--

Apr 1 '07 #2
<mr*******@gmail.comwrote:
<snip>
... . Everything works great in all browsers except in internet
explorer 6.0 ...
<snip>
<script type="text/javascript">
function click(name, title, susser, photographer, location)
<snip>
<img src="photos/guest/th256347_2Aguille du Midi 034.jpg"
onclick="click('256347_2Aguille du Midi 034.jpg', 'Crevasse Rescue
<snip>

You are suffering from a feature of web browsers that varies
considerably coinciding with a second variable feature and provoked by
your employing simplistic function names.

When a browser uses the text of an intrinsic event attribute (such as
onclick) in the HTML to create an event handling function it may or may
not create that function with an augmented scope chain, and browsers
that do this differ in the scope chains they create for such functions.
Internet Explorer does create its event handling functions with
augmented scope chains, and it puts the element that had the attribute
in its HTML at the top of that scope chain.

The second variable feature is that IE (and some, but not that many,
other browsers) implements a - click - method on its IMG elements.

When the event handling function created from your - onclick - attribute
is executed it executes - click( ... ); - and to do that it must resolve
the Identifier - click - against the scope chain. The Identifier will
resolve as a Reference to the value of the 'click' property of the first
object on the scope chain that has such a property. Without any scope
chain augmentation the Identifier resolution process would work down the
scope chain until it found the global object at the end of the chain.
Your globally defined - click - function is a property of the global
object named 'click' and so the Identifier would normally resolve as a
reference to that function.

However, with the augmentation, and with the IMG element now at the top
of the scope chain, when - click - is resolved the first object found on
the scope chain that has a 'click' property is the IMG element. The -
click - Identifier then resolves as a reference to the - click - method
of the IMG element and it is that method that is called. No error will
follow as you have just clicked the IMG element to trigger the event so
the effect of firing the IMG element's - click - method is unnoticeable.

There are lots of ways to deal with this issue, but I tend to think that
functions should be given names that state what they do. Now if your
function had a name that stated what it did that name would not be
'click'' and would be unlikely to coincide with any method on the any
object on any augmented scope chain (and if its name did correspond then
that would suggest that you already have a method that will do what your
function is attempting. That is, a function name like
'setImgFromThumbnail', while maybe a little cumbersome, is very unlikely
to clash with anything else.

Richard.

Apr 1 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

14
by: Terry A. Haimann | last post by:
I have been working on creating a dynamic web page and have made slow but steady progress. What I have now has an opening page with two drop down boxes. Based on a choice from the first box, the...
14
by: John Bentley | last post by:
Note this is crossposted to comp.lang.javacript and microsoft.public.dotnet.scripting. After some Googling and FAQing my understanding of these terms is, crudely: Javascript (3 different...
53
by: Cardman | last post by:
Greetings, I am trying to solve a problem that has been inflicting my self created Order Forms for a long time, where the problem is that as I cannot reproduce this error myself, then it is...
2
by: Dominic | last post by:
Hi everybody, I'm planning to use serialization to persist an object (and possibly its child objects) in my application. However, I'm concerned about the backward compatibility issue. I'm...
1
by: oreng | last post by:
Hey all, I have some problems detecting whether the client's browser javascript is enabled at the server side. While Request.Browser.JavaScript only check if the browser enable java script (and...
2
by: dwair | last post by:
Hi, I have been having browser compatibility issues and was wondering if anyone could help. I have been using a JavaScript array to populate marker data using ASP JS in a google Maps project. For...
12
by: Andy Dingley | last post by:
Assuming a large pile of legacy server-side JavaScript (reasonable quality ASP JScript from 2001-2002) what are the options for hosting it on some server-side platform that runs JavaScript ? ASP...
3
by: seza2b | last post by:
I've been developing a content management system over the past 5 months. Recently I began implementing AJAX and other misc. javascript into some pages. I was mainly developing and debugging using...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.