Any way to tell why "error" event is being thrown during imageloading?

K

Keith Hughitt

Hi all,

Anyone have any suggestions for finding out more information about why
an "error" event is thrown when creating an Image object via
JavaScript?

I am creating lots of images on the fly using PHP, and once and while
one will fail to load. Everything appears okay on PHP's end-- the
image is created and no errors are logged by Apache. I can catch the
error on the javascript end and replace it with another image, but I
haven't been able to track down what is causing the image to fail to
load in the first place? When an image does fail to load, refreshing
to page will fix the issue.

Any suggestions?

Thanks,
Keith
 
T

Thomas 'PointedEars' Lahn

Keith said:
Anyone have any suggestions for finding out more information about why
an "error" event is thrown when creating an Image object via
JavaScript?

Exceptions are thrown; events occur, or "are created" if you must.
I am creating lots of images on the fly using PHP, and once and while
one will fail to load. Everything appears okay on PHP's end-- the
image is created and no errors are logged by Apache. I can catch the
error on the javascript end and replace it with another image, but I
haven't been able to track down what is causing the image to fail to
load in the first place? When an image does fail to load, refreshing
to page will fix the issue.

Any suggestions?

Talk is cheap. Show me the code.
-- Linus Torvalds

<http://www.jibbering.com/faq/faq_notes/clj_posts.html#ps1Quest>


PointedEars
 
K

Keith Hughitt

Thanks for the correction.

Here is the code I'm using to create the image (uses Prototype):

var img,
rf = function () {
return false;
};

img = $(new Image());
img.addClassName('tile');
img.setStyle({
left: left + 'px',
top: top + 'px'
});
img.unselectable = 'on';

img.onmousedown = rf;
img.ondrag = rf;
img.onmouseover = rf;
img.oncontextmenu = rf;
img.galleryimg = 'no';
img.alt = "";


// If image doesn't exist, load the transparent tile in it's place
Event.observe(img, 'error', function(e) {
this.src = 'images/transparent.gif';
});

// Load Image
img.src = this.url

I set a breakpoint at the time the event occurs to make sure that the
URL (which is also generated based on some parameters), is correct,
and it is: If I copy and paste
the URL into a new tab, the image will display just fine.

-Keith
 
T

Thomas 'PointedEars' Lahn

Keith said:
Here is the code I'm using to create the image (uses Prototype):

Here I stopped reading. Prototype.js is junk. Come back when you have
learned to write scripts without invoking mystical incantations of your
fellow neophytes.


PointedEars
 

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,770
Messages
2,569,586
Members
45,086
Latest member
ChelseaAmi

Latest Threads

Top