Recent posts by Kite

Subscribe to Recent posts by Kite 1 post found

Jan 20, 2008
Kite 1 post

Topic: Script development / can't add an img onLoad event handler

Hi there, new to javascript. I'm trying to tweak the Craigslist image preview script (http://userscripts.org/scripts/show/6155) to screen out small images. Since the script doesn't know how big the images are until after they load, I'm trying to add an img onLoad event handler with this code:

img.onLoad = function () {
if (this.height < size) {
this.parentNode.removeChild(this);
}
}

This goes in about halfway thru the script, right after:

var img = $n("img",newA);
img.className = CLASS;
img.src = s;

Adding alerts, etc. indicates that the event handler isn't loading at all. Replacing "this" with "img" doesn't work either. Nor does this:

function checkSize () {
if (this.height < size) {
this.parentNode.removeChild(this);
}
}

.
.
.

img.onLoad = checkSize;

What am I doing wrong?