View Full Version : Script not working in IE, working in FF & Opera

06-18-2007, 03:37 PM
I wanted to make a js script that would take a few classnames from a MySQL DB and select all images with those classnames.

I did that with this part (this works):

new Ajax.Request( '/control/media/getClassNames', { onSuccess:
function (r) {
function( type ) {
var imgs = $$( 'img.' + type );
imgs.each(function(img) { //do some stuff }

so the php script returns a list of classnames JSON encoded. I use prototype js btw.

Those classnames mean a certain format for the picture, in this example cc_mediapreview, means maxwidth=290px and maxheight=190px. This way I can dynamically define the size of certain classes of pictures.

I used url="img_url" instead of src="img_url" to make sure that the browser doesn't try to load the (original)images at all.

Then in the //do some stuff I do this:

var url = img.getAttribute('url');
//Use ajax to see if temp img exists, if it doesn't exist it will be created on the fly
new Ajax.Request( '/control/media/temp_exists', { parameters: {
file: '/images/temp' + url.substring(url.lastIndexOf('/'),url.lastIndexOf('.')) + '_temp_' + type + url.substr(url.lastIndexOf('.')),
org_url: url,
class: type },
function (r) {
img.src = r.responseText;
} );

Again this works fine, it looks if there is a temp file and otherwise it creates one and echo's back the right src

First this was all I wanted, but what it does is it waits for the body onLoad event to execute it. This isn't good because all (original)images would have to be loaded first before they would get replaced by the right (temp)images

So I used a bit of code from http://www.brothercake.com/site/resources/scripts/domready/ so I could make it do all this before the images were loaded with:

var foobar = new domFunction(function () { imagesCCInit(); }, { 'img' : 'tag'});


is the function that makes a new object

var myImagesCC = null;
function imagesCCInit() {
myImagesCC = new imagesCC();

This is where it goes wrong in IE, it throws back an error Object Expected on line 9. That is the line with domFunctions. Why does it do this and how can I fix it?

You can check at http://www.clipcontrol.com that it works in both FF and Opera just great.

Thanks for any help!

06-18-2007, 08:50 PM
I would like to mention that if I just use:

Event.observe(window, 'load', imagesCCInit, false);

it works for all browsers.

Thanks again!

06-20-2007, 10:00 AM
Sorry for the bump, but can no one help me?