473,378 Members | 1,354 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.

Problem with some browsers when changing a displayed image

I have a small image on my web page that, when clicked, does some
javascript stuff which changes the page. To highlight that this has
happened, I want to replace the image with another. Each is a 16x16
pixel image.

The images are pre-loaded:

var image_g = new Image (16, 16);
var image_r = new Image (16, 16);
image_g.src = 'pics/arrow-g.jpg';
image_r.src = 'pics/arrow-r.jpg';
Then later when the user clicks on the image, I do (e.g.) this:

document.getElementById('pixie').src = image_g.src;

where pixie is an <imgin an <a hrefin a table cell.

This works fine in Safari, IE (Mac and XP), Netscape 7 (XP), and FireFox
2.0.0.1 (Mac). However it does not work in Netscape 6 (XP) and FireFox
2.0 (XP). The behaviour is as if the statement were commented out - I
get no Javascript errors, but the statement is ignored.

Am I somehow missing something which would make this completely standard
JS? Any clues appreciated.

Thanks,

-- tim
Jan 22 '07 #1
4 1354
Tim Streater wrote:
I have a small image on my web page that, when clicked, does some
javascript stuff which changes the page. To highlight that this has
happened, I want to replace the image with another. Each is a 16x16
pixel image.

The images are pre-loaded:

var image_g = new Image (16, 16);
var image_r = new Image (16, 16);
image_g.src = 'pics/arrow-g.jpg';
image_r.src = 'pics/arrow-r.jpg';
Then later when the user clicks on the image, I do (e.g.) this:

document.getElementById('pixie').src = image_g.src;
Why not the following?
document.getElementById('pixie').src = 'pics/arrow-g.jpg';

or

document.images['pixie'].src = 'pics/arrow-g.jpg';
// provided you have named your image space.

Mick
>
where pixie is an <imgin an <a hrefin a table cell.

This works fine in Safari, IE (Mac and XP), Netscape 7 (XP), and FireFox
2.0.0.1 (Mac). However it does not work in Netscape 6 (XP) and FireFox
2.0 (XP). The behaviour is as if the statement were commented out - I
get no Javascript errors, but the statement is ignored.

Am I somehow missing something which would make this completely standard
JS? Any clues appreciated.

Thanks,

-- tim
Jan 22 '07 #2
In article <45***********************@roadrunner.com>,
Michael White <mi**@mickweb.comwrote:
Tim Streater wrote:
I have a small image on my web page that, when clicked, does some
javascript stuff which changes the page. To highlight that this has
happened, I want to replace the image with another. Each is a 16x16
pixel image.

The images are pre-loaded:

var image_g = new Image (16, 16);
var image_r = new Image (16, 16);
image_g.src = 'pics/arrow-g.jpg';
image_r.src = 'pics/arrow-r.jpg';
Then later when the user clicks on the image, I do (e.g.) this:

document.getElementById('pixie').src = image_g.src;

Why not the following?
document.getElementById('pixie').src = 'pics/arrow-g.jpg';
That doesn't actually work either. According to Danny Goodman's JS
Bible, I should do what I am doing - in particular since sometimes I
want to assign it to image_r.src.

Today I discover that this *does* work in FireFox 1.5.0.9 under XP, but
not 2 or 2.0.0.1 under XP. So I'll downgrade on the XP machine for the
moment (if I can find it :-) to 1.5.0.9.
or

document.images['pixie'].src = 'pics/arrow-g.jpg';
// provided you have named your image space.
Nor familiar with this so I'll check in it. Thanks.

-- tim
Jan 23 '07 #3
In article <45***********************@roadrunner.com>,
Michael White <mi**@mickweb.comwrote:
Tim Streater wrote:
I have a small image on my web page that, when clicked, does some
javascript stuff which changes the page. To highlight that this has
happened, I want to replace the image with another. Each is a 16x16
pixel image.

The images are pre-loaded:

var image_g = new Image (16, 16);
var image_r = new Image (16, 16);
image_g.src = 'pics/arrow-g.jpg';
image_r.src = 'pics/arrow-r.jpg';
Then later when the user clicks on the image, I do (e.g.) this:

document.getElementById('pixie').src = image_g.src;

Why not the following?
document.getElementById('pixie').src = 'pics/arrow-g.jpg';

or

document.images['pixie'].src = 'pics/arrow-g.jpg';
// provided you have named your image space.
Nope. behaves identically.

-- tim
Jan 23 '07 #4
VK

Tim Streater wrote:
I have a small image on my web page that, when clicked, does some
javascript stuff which changes the page. To highlight that this has
happened, I want to replace the image with another. Each is a 16x16
pixel image.

The images are pre-loaded:

var image_g = new Image (16, 16);
var image_r = new Image (16, 16);
image_g.src = 'pics/arrow-g.jpg';
image_r.src = 'pics/arrow-r.jpg';
That is the key question I say _if_ they are preloaded. Image object
was added in Netscape 3.0 to better support newly introduced roll-over
effect: namely to avoid loading delays when passing for the _first
time_ over some roll-over image. On the second and any feature pass it
was irrelevant if you pre-loaded image or not: in either case it would
go w/o delay from the browser cache (I'm talking about conventional
images sent with no tricky response headers).
This way
var img = new Image();
img.src = 'path/to/image';
would mean "enforce loading and caching this image file"

This techniques was later adopted by IE 4 and others - but no one
AFAICT ever promised that forcing to cache something in such way will
work forever. So possibly on recent UAs Image functionality was
considered as not matching modern security and annoyance protection -
if it is indeed so then I could name at least several reasons. So
possibly extra cache-related functionality from Image object was
removed and now it is as abstract as:
var img = {
"src" : "path/to/image"
}

I am not using graphics roll-overs since about 2003, so I can say
nothing for sure. Some testing to check it out would be great.

Jan 23 '07 #5

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

Similar topics

32
by: Werner Partner | last post by:
Hier is the problem: http://asterix/sonoptikon.de/artemis/index.php The <h1> and <h2> make their ellbows so broad that in the picture arise borders on top and bottom. The general question is:...
6
by: Robert Lapes | last post by:
I'm just getting into using CSS and I'm having a problem getting Opera to display a Navigation Bar in the same way as IE6. Can someone please point me in the right direction? The site I'm...
4
by: VR | last post by:
First, greetings to everyone :) I'm doing a university seminar & I've encountered a problem. I have a gallery with thumbnails linked on pictures. What I want is popup to be opened with...
4
by: Saso Zagoranski | last post by:
Hi! Here is what I'm trying to do: I have created a UserControl named PictureView. It holds all the images in one directory in the Bitmap images variable. The selected image is displayed in...
3
by: Larry | last post by:
I've set up a list of image filesnames in a listview control(lvSrcFileList), I'm using the selectedIndexChange event to select which file is being displayed in a picturebox control(pbImagePreview)....
7
by: Andrew Christiansen | last post by:
Hey everyone. I have Visual Basic .NET 2003 and am trying to show images on a treeview control. I have the imagelist on the form filled with images, and have the ImageList property of the...
3
by: Mark Szlazak | last post by:
The following page simulates a pool cue and cue ball: http://members.aol.com/myscript/cue.html Mouse cursor position around the cue ball determines where a roll-over of 179 pool cue images is...
23
by: Peter | last post by:
I have a problem with a page show_image.asp that returns a jpg image under Windows XP Pro SP2. The page sets content type as: Response.ContentType = "image/jpg" While this works perfectly fine...
4
by: STIAdmin | last post by:
Happy Holidays to all of you! This is my first time posting. I'm working on a web project and trying to get this done before Christmas. The limitation is that I'm using an out of the box program...
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
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: 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
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
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 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.