I am currently using fineuploader with ASP.NET webforms and am encountering a problem with strict mode in FireFox. ASP.NET webforms has a javascript file (microsoftajaxwebforms.js) that contains the following code (This is used to postback to the server and call the passed event, ex. Save
below.):
_doPostBack: function(a, k) {
var f = window.event;
if (!f) {
var d = arguments.callee ? arguments.callee.caller : null;
if (d) {
var j = 30;
while (d.arguments.callee.caller && --j) d = d.arguments.callee.caller;
f = j && d.arguments.length ? d.arguments[0] : null
}
}
...
That function is used liberally in the codebase I am working with. I cannot change this code for fear of unintended side-effects in the rest of the product. The problem is with the arguments.callee.caller
. That is what is throwing the error access to strict mode caller function is censored
. I believe the solution is to remove the use strict
from the fineuploader.js, but I am worried about how that might effect fineuploader in other browsers. I am not familiar with strict mode in javascript, so maybe someone can shed some light on the possible side-effects of removing strict mode from the fineuploader.js. For reference, here is the fineuploader function that eventually calls the above code and causes the error.
var fineUploader = $('#jquery-wrapped-fine-uploader').fineUploader({
...
multiple: false,
text: {
uploadButton: 'Click or drag a file to upload.'
},
autoUpload: false,
debug: false,
template: 'fineuploader-template',
...
}
}).bind('complete', function (event, id, name, response) {
if (response['success']) {
cp_hide();
fineUploader.fineUploader('reset');
__doPostBack("Save", "");
}
})...
I can modify anything short of the code referenced from microsoftajaxwebforms.js
if needed. I appreciate any help.
The workaround according to the jQuery ticket (http://bugs.jquery.com/ticket/13335) is to manually call the event on the client side rather than calling __doPostBack
directly.
$('#Save').trigger('click');
However, if you are trying to trigger a postback from within the client-side event, the trigger
option won't work. Instead, you can use ugly, yet trusty setTimeout
to get out of strict
mode.
$('#Save').on('click', function(e) {
var result = doSomeStuff();
if(result.success) {
window.setTimeout(function() { __doPostBack('Save', '') }, 5);
}
// ...
});
jQuery eventually removed use strict
2 years ago, so upgrading the jQuery (if possible) should also solve the issue.