Skip to content

Commit 81b4c68

Browse files
committed
Merge pull request nervgh#159 from edzius/master
Fix iframe error response handling on IE browsers
2 parents 5931469 + cea398a commit 81b4c68

File tree

1 file changed

+17
-4
lines changed

1 file changed

+17
-4
lines changed

src/scripts/services/$fileUploader.js

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -395,10 +395,23 @@ app.factory('$fileUploader', ['$compile', '$rootScope', '$http', '$window', func
395395
});
396396

397397
iframe.bind('load', function() {
398-
// fixed angular.contents() for iframes
399-
var html = iframe[0].contentDocument.body.innerHTML;
400-
var xhr = {response: html, status: 200, dummy: true};
401-
var response = that._transformResponse(xhr.response);
398+
var response;
399+
var xhr = {response: response, status: 200, dummy: true};
400+
// Fix for legacy IE browsers that loads internal error page
401+
// when failed WS response received. In consequence iframe
402+
// content access denied error is thrown becouse trying to
403+
// access cross domain page. When such thing occurs notifying
404+
// with empty response object. See more info at:
405+
// http://stackoverflow.com/questions/151362/access-is-denied-error-on-accessing-iframe-document-object
406+
// Note that if non standard 4xx or 5xx error code returned
407+
// from WS then response content can be accessed without error
408+
// but 'XHR' status becomes 200. In order to avoid confusion
409+
// returning response via same 'success' event handler.
410+
try {
411+
// fixed angular.contents() for iframes
412+
xhr.response = iframe[0].contentDocument.body.innerHTML;
413+
response = that._transformResponse(xhr.response);
414+
} catch (e) {}
402415
that.trigger('in:success', xhr, item, response);
403416
that.trigger('in:complete', xhr, item, response);
404417
});

0 commit comments

Comments
 (0)