这是在为学院做精品课程网站的时候遇到的一个问题,老师提供的资料都是pdf格式的,如果访问者的计算机上没有装acrobat reader,直接用iframe或者直接用链接打开,那就不是打开文档,而是直接下载了,为了防止下载,
想像到媒体文件的播放方式,加上一些官方的docs,考虑用用object标签使用pdf插件嵌入ie中,结果可行。
代码如下:
< DIV id =showdiv
style =”Z-INDEX: 0; LEFT:10px; WIDTH: 10px; POSITION: absolute; TOP: -30px; HEIGHT: 10px” >
< object classid =”clsid:CA8A9780-280D-11CF-A24D-444553540000″ width =”1000″ height =”700″ border =”0″ top =”-10″ name =”pdf” >
< param name =”toolbar” value =”false” >
< param name =”_Version” value =”65539″ >
< param name =”_ExtentX” value =”20108″ >
< param name =”_ExtentY” value =”10866″ >
< param name =”_StockProps” value =”0″ >
< param name =”SRC” value =”name.pdf ”>
</ object >
</ DIV >
这样防止了没有安装阅读器的访问者下载文件,然而,在没有安装acrobat reader的情况下,网页显示一片空白,没有任何提示用户安装的阅读器的信息,这对做网页设计的人来说是个大忌,又想到用activeX的方式,结果以 失败告终,最后只好采用javascript的方式,用try{..}catch{..}的方式来捕获创建activeX对象中产生的异常,这种方式只能 验证单个版本的acrobat reader ,也被淘汰,用google搜索了下E文站点,发现这个问题在国外的一些论坛上很多,而且解决方法也很多,经过测试,最终决定采用的代码如下:
< HTML >
< HEAD >
< META http-equiv ="Content-Type" content ="text/html; charset=gb2312" >
< META http-equiv ="Content-Style-Type" content ="text/css" >
< META http-equiv ="Content-Script-Type" content ="text/javascript" >
< TITLE > Checking if Acrobat Reader installed (IE4+)... </ TITLE >
< SCRIPT for ="window" event ="onload"
代码如下:
< DIV id =showdiv
style =”Z-INDEX: 0; LEFT:10px; WIDTH: 10px; POSITION: absolute; TOP: -30px; HEIGHT: 10px” >
< object classid =”clsid:CA8A9780-280D-11CF-A24D-444553540000″ width =”1000″ height =”700″ border =”0″ top =”-10″ name =”pdf” >
< param name =”toolbar” value =”false” >
< param name =”_Version” value =”65539″ >
< param name =”_ExtentX” value =”20108″ >
< param name =”_ExtentY” value =”10866″ >
< param name =”_StockProps” value =”0″ >
< param name =”SRC” value =”name.pdf ”>
</ object >
</ DIV >
这样防止了没有安装阅读器的访问者下载文件,然而,在没有安装acrobat reader的情况下,网页显示一片空白,没有任何提示用户安装的阅读器的信息,这对做网页设计的人来说是个大忌,又想到用activeX的方式,结果以 失败告终,最后只好采用javascript的方式,用try{..}catch{..}的方式来捕获创建activeX对象中产生的异常,这种方式只能 验证单个版本的acrobat reader ,也被淘汰,用google搜索了下E文站点,发现这个问题在国外的一些论坛上很多,而且解决方法也很多,经过测试,最终决定采用的代码如下:
< HTML >
< HEAD >
< META http-equiv ="Content-Type" content ="text/html; charset=gb2312" >
< META http-equiv ="Content-Style-Type" content ="text/css" >
< META http-equiv ="Content-Script-Type" content ="text/javascript" >
< TITLE > Checking if Acrobat Reader installed (IE4+)... </ TITLE >
< SCRIPT for ="window" event ="onload"
<!--
document.all [
document.all.PDFNotKnown ? "IfNoAcrobat" : "IfAcrobat"
] .style.display = "block";
//--></SCRIPT>
</HEAD>
<BODY>
<NOSCRIPT>
Cannot determine if you have Acrobat Reader (or the full Acrobat)
installed <FONT size="-1">(because JavaScript is unavailable or
turned off)</FONT>.
</NOSCRIPT>
<DIV id="IfNoAcrobat" style="display:none">
你需要先安装Adobe Reader才能正常浏览文件,请点击这里下载Adobe Reader.
</DIV>
<OBJECT type="application/pdf" width=0 height=0 style="display:none">
<DIV id="PDFNotKnown" style="display:none"> </DIV>
</OBJECT>
</BODY>
</HTML>
方法二:
$name="./deng.pdf";
$fp=fopen($name,'rb');
header("Content-Type:application/pdf");
header("Content-Length:".filesize($name));
fpassthru($fp);
exit;
document.all [
document.all.PDFNotKnown ? "IfNoAcrobat" : "IfAcrobat"
] .style.display = "block";
//--></SCRIPT>
</HEAD>
<BODY>
<NOSCRIPT>
Cannot determine if you have Acrobat Reader (or the full Acrobat)
installed <FONT size="-1">(because JavaScript is unavailable or
turned off)</FONT>.
</NOSCRIPT>
<DIV id="IfNoAcrobat" style="display:none">
你需要先安装Adobe Reader才能正常浏览文件,请点击这里下载Adobe Reader.
</DIV>
<OBJECT type="application/pdf" width=0 height=0 style="display:none">
<DIV id="PDFNotKnown" style="display:none"> </DIV>
</OBJECT>
</BODY>
</HTML>
方法二:
$name="./deng.pdf";
$fp=fopen($name,'rb');
header("Content-Type:application/pdf");
header("Content-Length:".filesize($name));
fpassthru($fp);
exit;