3

I wrote an extedned plugin based on jCrop to crop mulitple images one after another.

I developed and debugged using Chrome and everything worked fine without any JavaScript issues. When i came to test in Explorer it fell over and threw a script error that wrote out

jcrop api is null or not an object

So my javascript is simply...

var jcrop_api; //Global var to be used thorugh out the client

//some code here

//jCrop documention tells us to use this to assign itself to an object.
//I look for both because i use .net masterpages and sometimes not.

$('#SourceImage, #body_SourceImage').Jcrop({},function () { jcrop_api = this; });


//some more code but not far down the line i need to set jCrop options using API

jcrop_api.setOptions({
           boxWidth: bw,
           onSelect: updateCoords,
           minSize: [thisImage.Min.Width, thisImage.Min.Height],
           aspectRatio: thisImage.AspectRatio
       });
 jcrop_api.setImage('../cache/uploads/' + fileName);

That all work in Chrome and i can change images using a global trigger. I have no idea why it does not work in IE?

4

1 回答 1

8

事实上,jCrop 确实在文档中显示了您使用的确切行。但是 IE JavaScript 引擎是无情的。

您需要做的是使用此行将 api 分配给 var

var jcrop_api;

$(document).ready(function () {

jcrop_api = $.Jcrop($('#SourceImage, #body_SourceImage'), {});

然后做剩下的。出于某种原因this,在 IE 中引用回整个 DOM 而不是 jCrop 的回调函数并且无法分配,从而使您的 API 变量一无所有。

此更改不会影响 Chrome、FF 或其他任何东西.. 并且更清晰一点。

于 2012-04-18T13:14:16.390 回答