我在使用IE8中的window.URL时遇到问题。有人可以请帮忙。我试图让IE8中的window.URL工作。请遵循以下代码。试图获得IE8中的window.URL。获取未定义的错误
<!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>
实际的问题是在一个新的窗口,一个PDF页面显示PDF数据(arraybuffer)。 PDF不应该被下载到TEMP文件夹。
步骤: 我从RESTful AJAX调用获取arraybuffer响应。 将其转换为JS中的BLOB。 在IE8中不支持BLOB,但我在blob构造函数上面添加了。现在我在window.URL面临的问题,因为我不能够使用window.URL.createObjectURL(BLOB)到BOLB转换为文档的网址
请参加下面的代码看看:
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......
确实window.location适合你吗? –
_“在IE8中使用window.URL时遇到问题”_请参阅“浏览器兼容性”中的“Blob”https://developer.mozilla.org/en-US/docs/Web/API/Blob#Browser_compatibility,不会出现可用,直到版本10的ie – guest271314
@BrijRajSingh是的window.location工作,并给了我该HTML文件的路径。 –