弹出打开pdf不适用于Internet Explorer

时间:2016-10-04 14:21:14

标签: javascript internet-explorer

我使用一个小的java脚本在较小的标签中打开pdf文档:



// JavaScript Document
function openHeyPopup(objectLink) {

	window.open(objectLink, "Externer Link",  "width=700,height=600,scrollbars=yes");

}

function initHeyPopup()
{
	
	if (!document.getElementsByTagName){ return; }
	var anchors = document.getElementsByTagName("a");

	// loop through all anchor tags
	for (var i=0; i<anchors.length; i++){
		var anchor = anchors[i];

		if (anchor.getAttribute("href") && (anchor.getAttribute("rel") == "heypopup")){
			anchor.onclick = function () {openHeyPopup(this); return false;}
		}
	}

}

function addLoadEvent(func)
{	
	var oldonload = window.onload;
	if (typeof window.onload != 'function'){
    	window.onload = func;
	} else {
		window.onload = function(){
		oldonload();
		func();
		}
	}

}

addLoadEvent(initHeyPopup);	// run initLightbox onLoad
&#13;
&#13;
&#13;

这适用于chrome和firefox。但在Internet Explorer中我得到一个空的浏览器窗口。

http://www.interieursalon.com/wp/wp-content/uploads/2016/08/web-interieursalon-portfolio.pdf

任何人都无法解决这个问题吗?

祝你好运

1 个答案:

答案 0 :(得分:0)

由于安全原因,在IE中,会阻止打开包含不安全内容的新标签页。我们可以尝试以下代码,这有助于我们下载文件。

//window.navigator checks for IE version if yes, it gets executed and in place of  data give your blob.

if (window.navigator && window.navigator.msSaveOrOpenBlob) {
            return window.navigator.msSaveOrOpenBlob(data, "data.pdf");
}