Firefox perfect, problems with IE

E

edfialk

Hello all, I have this web application up at http://niceguy.wustl.edu/NEISGEI/EmisComp.
It's for visually comparing emission data.

So, I added this nice loading animated gif to the maps to show users
that the image is still downloading (some data can take a couple of
minutes). I found the script somewhere on the web.

Unfortunately, it doesn't work in Internet Explorer (surprise...)

So, I have 3 maps, 3 loading gifs, 3 loading divs. I'm only showing
the addLoadEvent function for one, but here's the script:

document.write('<div id="loading1"><img src="load.gif"></div>');
document.write('<div id="loading2"><img src="load.gif"></div>');
document.write('<div id="loading3"><img src="load.gif"></div>');

function addLoadEvent1(func) {
var oldonload = window.onload;
if (typeof window.onload != 'function') {
window.onload = func;
} else {
window.onload = function() {
if (oldonload) {
oldonload();
}
func();
}
}
}

addLoadEvent1(function() {
document.getElementById("loading1").style.display="none";
});



Any ideas what the IE problem is?
Thanks!
-Ed
 
R

RobG

Hello all, I have this web application up athttp://niceguy.wustl.edu/NEISGEI/EmisComp.
It's for visually comparing emission data.

So, I added this nice loading animated gif to the maps to show users
that the image is still downloading (some data can take a couple of
minutes). I found the script somewhere on the web.

Unfortunately, it doesn't work in Internet Explorer (surprise...)

So, I have 3 maps, 3 loading gifs, 3 loading divs. I'm only showing
the addLoadEvent function for one, but here's the script:

document.write('<div id="loading1"><img src="load.gif"></div>');
document.write('<div id="loading2"><img src="load.gif"></div>');
document.write('<div id="loading3"><img src="load.gif"></div>');

It is more efficient to concatenate the strings and call
document.write once:

document.write(
'<div id="loading1"><img src="load.gif"></div>' +
'<div id="loading2"><img src="load.gif"></div>' +
'<div id="loading3"><img src="load.gif"></div>'
);

function addLoadEvent1(func) {
var oldonload = window.onload;
if (typeof window.onload != 'function') {
window.onload = func;
} else {
window.onload = function() {
if (oldonload) {
oldonload();
}
func();
}
}
}

That is an old method, though still quite effective. There are others
that use a mix of attachEvent and addEventListener (search the
archives[1]). A better version of the above is:


function addLoadEvent1(func) {
var oldonload = window.onload;
if (typeof oldonload == 'function') {
window.onload = function(){
oldonload();
func();
}
} else {
window.onload = func;
}
}

There is a minor issue that if used extensively, the closures that are
formed may consume more memory than you realise. However, it may not
use much more than would have been consumed using addEventListener/
attachEvent, just be aware of it.


1. The following link has a good discussion:
<URL:
http://groups.google.com.au/group/c...for+attachEvent&rnum=1&hl=en#93561d5a2ebdb4aa
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,014
Latest member
BiancaFix3

Latest Threads

Top