I am facing problem in using window.URL in IE8. Could someone please help. I am trying to get window.URL working in IE8. Please following code.
<!DOCTYPE html>
<html>
<head>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type">
</head>
<body>
<p>This text should be red.</p>
<script>
window.Blob = Blob = function (b) {
return {
data: b
};
};
var myBlob;
window.URL = window.URL || window.webkitURL;
console.log('URL '+URL );
if (window.Blob) {
console.log('Check URL => '+URL );
console.log('Check window.URL => '+window.URL );
console.log('Check window.Blob => '+window.Blob );
myBlob = new Blob(['body { color: red; }'], {type: 'text/css'});
appendLinkElement();
alert("The Blob() constructor was used.");
}else {
console.log('Check URL => '+URL );
console.log('Check window.URL => '+window.URL );
console.log('Check window.Blob => '+window.Blob );
document.getElementsByTagName('body')[0].innerHTML = "<h3>Blob objects not supported - please upgrade your browser.</h3>";
}
function appendLinkElement() {
var link = document.createElement('link');
link.rel = 'stylesheet';
link.href = window.URL.createObjectURL(myBlob);
document.body.appendChild(link);
}
</script>
</body>
</html>
Actual problem is displaying PDF data (arraybuffer) on a new window as a PDF page. PDF should not be downloaded to TEMP folder.
steps:
I am getting arraybuffer response from a RESTful AJAX call.
Converting that to BLOB in JS.
BLOB is not supported in IE8 but I added above blob constructor. Now I am facing problem in window.URL as I am not able to convert BOLB to doc URL using window.URL.createObjectURL(blob)
Please take a look in following code:
searchService.viewDocument(docId)
.success(function(data, status, headers, config) {
if (window.Blob) {
var blob = new Blob([data], {type: "application/pdf"}); //IF BLOB constructor added this will work for IE8
console.log("window "+window);
console.log("window.URL "+window.URL);
console.log("window.webkitURL "+window.webkitURL);
console.log("window.mozURL "+window.mozURL);
console.log("window.msURL "+window.msURL);
var URLLink = window.URL || window.webkitURL || window.mozURL || window.msURL;
console.log('URLLink ='+URLLink ); // this is NULL OR UNDEFINED in IE8 Code works in other browsers like Chrome and IE11
var fileURL = URLLink.createObjectURL(blob);
$scope.content = $sce.trustAsResourceUrl(fileURL); //AngularJS code
var pdfWindow = window.open("", "PDF View", "width=1833, height=1000");
var pdfHtmlData = '<head><title>PDF View</title></head><body><div ><object width="1833" height="1000" data="' + $scope.content + '" type="application/pdf"></object></div></body>';
pdfWindow.document.write(pdfHtmlData);
}else{
console.log("viewDocument BLOB not supported.");
}
}).error......