试图让window.URL在IE8工作。获取未定义错误 [英] trying to get window.URL working in IE8. Getting Undefined Error
问题描述
我在使用IE8面临window.URL问题。可能有人请帮助。我试图让window.URL在IE8工作。请以下code。
<!DOCTYPE HTML>
< HTML和GT;
< HEAD>
<元CONTENT =text / html的;字符集= UTF-8HTTP的当量=Content-Type的> < /头> <身体GT;
< P>这文字应该是红色和LT; / P>
<脚本>
window.Blob =斑点=功能(B){
返回{
数据:乙
};
}; VAR myBlob; window.URL = window.URL || window.webkitURL; 的console.log('URL'+ URL);
如果(window.Blob){
的console.log('检查URL =>'+ URL);
的console.log('检查window.URL =>'+ window.URL);
的console.log('检查window.Blob =>'+ window.Blob);
myBlob =新的Blob(['身体{颜色:红色;}'],{类型:文字/ CSS'});
appendLinkElement();
警报(被使用的斑点()构造函数。);
}其他{
的console.log('检查URL =>'+ URL);
的console.log('检查window.URL =>'+ window.URL);
的console.log('检查window.Blob =>'+ window.Blob);
document.getElementsByTagName('身体')[0] .innerHTML =< H3方式>的Blob对象不支持 - 请升级浏览器和LT; / H3>中;
} 功能appendLinkElement(){
VAR链接=使用document.createElement('链接');
link.rel ='样式表;
link.href = window.URL.createObjectURL(myBlob);
document.body.appendChild(链接);
}
< / SCRIPT>
< /身体GT;< / HTML>
实际的问题是在一个新的窗口,为PDF页面显示PDF数据(arraybuffer)。 PDF不应该被下载到TEMP文件夹。结果
脚步:
我正在从一个RESTful AJAX调用arraybuffer响应。
转换,要在BLOB JS。
BLOB不支持IE8,但我上面的blob构造补充说。现在我面临的问题在window.URL因为我不能够使用到BOLB转换为文档的网址window.URL.createObjectURL(BLOB)
请采取以下code一看:
searchService.viewDocument(的docId)
.success(功能(数据,状态,头,配置){
如果(window.Blob){
VAR BLOB =新的Blob([数据] {类型:应用程序/ PDF}); //如果BLOB构造增加,这将IE8的工作 的console.log(窗口+窗口);
的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); //这是在其他浏览器Chrome和IE8 IE11 code ++工程null或undefined VAR fileURL = URLLink.createObjectURL(BLOB);
$ scope.content = $ sce.trustAsResourceUrl(fileURL); // AngularJS code VAR pdfWindow = window.open(,PDF浏览,宽= 1833,高度= 1000);
VAR pdfHtmlData ='< HEAD><标题> PDF查看< /标题>< /头><身体GT;< DIV><对象宽度=1833HEIGHT =1000数据=+ $ scope.content +'类型=应用/ PDF>< /对象>< / DIV>< /身体GT;';
pdfWindow.document.write(pdfHtmlData);
}其他{
的console.log(不支持viewDocument BLOB。); } })。错误......
您可以使用window.location的,它包含了你需要的一些信息。
使用此code:
window.location.href
您可以看到该对象的样本波纹管
{散列:,主持人:st.msc.ir,主机名:domain.com中,href:HTTP:// ......,路径:/login.aspx,端口: 协议:HTTP:搜索:RETURNURL = ...}
如果你想没有任何code更改您的code之前加入这行来解决你的问题。
window.URL = window.URL window.URL:window.location.href;
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......
you can use window.location ,it contains some information that you need.
Use this code: window.location.href
you can see a sample of this object bellow
{hash: "", host: "st.msc.ir", hostname: "domain.com", href: "http://...", pathname: "/login.aspx", port: "", protocol: "http:", search: "?ReturnUrl=..."}
If you want to solve your problem without any code changing add this line before your code
window.URL=window.URL?window.URL:window.location.href;
这篇关于试图让window.URL在IE8工作。获取未定义错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!