I'm trying to use a javascript function that works in IE but not in Firefox.
Is there something about this code that is IE specific? If so, can I
add/alter something to make it work in more browsers?
Ex:<img src="thumbs/Dina.jpg" alt="Dina Marie Vannoni" width="39"
height="50" border="1" onClick="enlarge()"><script language="JavaScript">
function enlarge() {
oSrcElem = event.srcElement;
imgLarge.src = oSrcElem.src.replace(/thumbs/,'images');
}
</script>
Thanx,Wm(replies CC: to sdshooter at hotmail appreciated!) 6 2118
LAshooter wrote: I'm trying to use a javascript function that works in IE but not in Firefox. Is there something about this code that is IE specific? If so, can I add/alter something to make it work in more browsers?
Yes, and yes.
Ex:<img src="thumbs/Dina.jpg" alt="Dina Marie Vannoni" width="39" height="50" border="1" onClick="enlarge()"><script language="JavaScript">
The language attribute is depreciated, type is required.
function enlarge() { oSrcElem = event.srcElement;
Your use of 'event' here is the issue. IE uses a global 'event' that
is always available, Geko browsers don't. Depending on how you attach
your onclick, you may have to pass 'event' to the function. Then there
are a few things you need to do in the function to tidy-up.
... onClick="enlarge(event)">
<script type="text/javascript">
function enlarge(e) {
e = e || window.event; // fits both event models
var oSrcElem = e.target || e.srcElement; // fits both IE & others
imgLarge.src = oSrcElem.src.replace(/thumbs/,'images');
where does 'imgLarge' come from? If it's the id of an image element,
then it will work in IE 'cos it uses ids as global variables, but...
Other browsers don't. You could use the images collection but you'll
probably settle for getElementById.
You may want to look at the group FAQ for how to support older IE and
document.all:
<URL:http://www.jibbering.com/faq/#FAQ4_15>
} </script> Thanx,Wm(replies CC: to sdshooter at hotmail appreciated!)
What's said in the group stays in the group...
--
Rob
Well, yes, srcElement is IE, mozilla uses .target, same object really,
now, you don't need it though, as you're using an event handler on the
actual element explicitly as opposed to binding it through its hierarchy,
so, instead, use:
function enlarge(el) {
el.src=el.src.replace(/thumbs/,'images')
}
onclick="enlarge(this)"
Danny
On Sun, 26 Jun 2005 18:04:35 -0700, LAshooter <la*******@hotmail.com>
wrote: I'm trying to use a javascript function that works in IE but not in Firefox. Is there something about this code that is IE specific? If so, can I add/alter something to make it work in more browsers?
Ex:<img src="thumbs/Dina.jpg" alt="Dina Marie Vannoni" width="39" height="50" border="1" onClick="enlarge()"><script language="JavaScript"> function enlarge() { oSrcElem = event.srcElement; imgLarge.src = oSrcElem.src.replace(/thumbs/,'images'); } </script> Thanx,Wm(replies CC: to sdshooter at hotmail appreciated!)
--
Using Opera's revolutionary e-mail client: http://www.opera.com/mail/
Danny wrote: Well, yes, srcElement is IE, mozilla uses .target, same object really, now, you don't need it though, as you're using an event handler on the actual element explicitly as opposed to binding it through its hierarchy, so, instead, use:
function enlarge(el) { el.src=el.src.replace(/thumbs/,'images') }
onclick="enlarge(this)"
This is error-prone and does not degrade cleanly.
1. Having Thumbnails in a sibling directory is hardly good resource
management. Thumbnails should be located in a subdirectory or
(even better) in the same directory with slightly different
filenames.
2. What if a filename contains `thumbs'?
3. What if the replace() method or RegExp literals are not supported
accordingly?
4. What if the element is clicked twice?
5. What about users that don't have or don't want to use a pointing device?
6. What about users with client-side scripting disabled or just not
available?
On Sun, 26 Jun 2005 18:04:35 -0700, LAshooter <la*******@hotmail.com> wrote: [...]
Please stop top-posting, and please stop cross-posting without Followup-To.
<http://jibbering.com/faq/>
PointedEars
JRS: In article <17****************@PointedEars.de>, dated Thu, 14 Jul
2005 18:53:58, seen in news:comp.lang.javascript, Thomas 'PointedEars'
Lahn <Po*********@web.de> posted : please stop cross-posting without Followup-To. <http://jibbering.com/faq/>
Ignore the ramblings of this juvenile control freak. He has a Fuhrer-
complex.
I see nothing in the newsgroup FAQ about cross-posting of follow-ups,
and I know of no such requirement in general Usenet standards.
However, it is generally considered rude to set follow-up without
explicitly saying so in the body of the article.
--
© John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 IE 4 ©
<URL:http://www.jibbering.com/faq/> JL/RC: FAQ of news:comp.lang.javascript
<URL:http://www.merlyn.demon.co.uk/js-index.htm> jscr maths, dates, sources.
<URL:http://www.merlyn.demon.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.
Thomas 'PointedEars' Lahn wrote: Please stop top-posting, and please stop cross-posting without Followup-To. <http://jibbering.com/faq/>
And this coming from someone who set the follow-up to a newsgroup that
is of questionable integrity/quality over a newsgroup that is chartered,
the *official* (J)ava/ECMAScript newsgroup, and proven to be of quality
and integrity?
WOW.
--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
Dr John Stockton wrote: JRS: In article <17****************@PointedEars.de>, dated Thu, 14 Jul 2005 18:53:58, seen in news:comp.lang.javascript, Thomas 'PointedEars' Lahn <Po*********@web.de> posted :
please stop cross-posting without Followup-To. <http://jibbering.com/faq/>
Ignore the ramblings of this juvenile control freak. He has a Fuhrer- complex. [...]
Ahh, eventually you do show your true face.
Godwin's Law. You lose.
PointedEars This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Steven Green |
last post by:
I did a clean install of Windows XP on my computer and my javascript will
not work. I've tried all types of browsers, I've download the Service pack
1 for XP and IE. I have download java from...
|
by: LRW |
last post by:
(Sorry if this is a repost...my newsreader keeps crashing on the
posting--I don't know if the message going out or not)
For some reason this javascript just won't work in Firefox. It works
fine...
|
by: b. hotting |
last post by:
Hi,
I don't see why this won't work,
it are 3 links, the last one (a get) does work, but the first 2 won't.
i would like to use a post, through hidden input types
any idea?
thanks for your...
|
by: Igal |
last post by:
hay. i'm working on some site, the code is pretty old, it has some form
validation JS scripts. but seems like they work only in IE, won't work
with FireFox. here's a example:
<script...
|
by: Altman |
last post by:
I have created an ascx control and I am calling
registerclientscriptblock. The path to the js file is relative to the
aspx page and not the ascx file. The function runs fine in IE7 but in...
|
by: Sky Kast |
last post by:
I'm running Firefox on a win 98 computer and javascript won't work
And yes i have set everything javascript that should enable to true or check so it's not that
|
by: neoseeker191 |
last post by:
It works fine in Firefox 2+ but in IE7 the alert window doesnt appear and the script doesnt work.
Maybe I'm missing something
Heres the form the script is tied to:
<form id="Quiz"...
|
by: Matthew Wells |
last post by:
Hello. I'm reposting this because my prioe post's subject line was
incorrect.
I'm developing an asp.net 2.0 project using VS 2005 on XP sp2 with all
the updates. I have an aspx page with...
|
by: tjc0ol |
last post by:
Hi all,
I made contact page which allows visitors to input their name, email address, phone number, comments and select a comment type by using <select> element in html with javascript. Among the...
|
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: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
| |