Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/194.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 避免在智能手机上自动下载pdf_Javascript_Android_Html - Fatal编程技术网

Javascript 避免在智能手机上自动下载pdf

Javascript 避免在智能手机上自动下载pdf,javascript,android,html,Javascript,Android,Html,我为一个朋友写了一个非常简单的网站,他需要在页面中显示pdf。 首先,我尝试使用iframe,但无法将高度设置为“100%” /* *当iframe位于不同的子域上时,请取消对以下行的注释 *并将“example.com”更改为您的域。 */ //document.domain=“example.com”; 函数设置iframe高度(iframe){ if(iframe){ var iframeWin=iframe.contentWindow | | iframe.contentDocumen

我为一个朋友写了一个非常简单的网站,他需要在页面中显示pdf。 首先,我尝试使用iframe,但无法将高度设置为“100%”


/*
*当iframe位于不同的子域上时,请取消对以下行的注释
*并将“example.com”更改为您的域。
*/
//document.domain=“example.com”;
函数设置iframe高度(iframe){
if(iframe){
var iframeWin=iframe.contentWindow | | iframe.contentDocument.parentWindow;
if(iframeWin.document.body){
iframe.height=iframeWin.document.documentElement.scrollHeight | | iframeWin.document.body.scrollHeight;
}
}
};
window.onload=函数(){
setIframeHeight(document.getElementById('mainContent');
};
这是主体部分的iframe

<iframe id="mainContent" src="URL_PDF" scrolling=auto frameborder=0  width="100%"></iframe>


它可以工作,但当我尝试用智能手机访问页面时出现了一个问题(我用安卓系统进行了测试)。特别是,浏览器试图下载文件而不是显示它,有一种方法可以避免吗?

我使用库pdf.js获得了解决方案
<iframe id="mainContent" src="URL_PDF" scrolling=auto frameborder=0  width="100%"></iframe>