Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/joomla/2.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并显示消息以使用jquery下载Adobe reader?_Javascript_Jquery_Css_Pdf_Xhtml - Fatal编程技术网

Javascript 如何检测页面上的链接PDF并显示消息以使用jquery下载Adobe reader?

Javascript 如何检测页面上的链接PDF并显示消息以使用jquery下载Adobe reader?,javascript,jquery,css,pdf,xhtml,Javascript,Jquery,Css,Pdf,Xhtml,如果页面链接了.pdf文件,则应将中的消息添加到#maintentdiv末尾之前,作为最后一段 例如,这是默认的html <div id="maincontent"> <ul class="cheat_sheet_downloads"> <li><a href="http://www.addedbytes.com/download/css-cheat-sheet-v2.pdf">PDF, 316Kb</a></li> <

如果页面链接了.pdf文件,则应将
中的消息添加到
#maintent
div末尾之前,作为最后一段

例如,这是默认的html

<div id="maincontent">
<ul class="cheat_sheet_downloads">
<li><a href="http://www.addedbytes.com/download/css-cheat-sheet-v2.pdf">PDF, 316Kb</a></li>
<li><a href="http://www.addedbytes.com/download/css-cheat-sheet-v3.pdf/">PNG, 77Kb</a></li>
</ul>
<div>

检测到pdf后

应该是这样的

<div id="maincontent">
    <ul class="cheat_sheet_downloads">
    <li><a href="http://www.addedbytes.com/download/css-cheat-sheet-v2.pdf/">PDF, 316Kb</a></li>
    <li><a href="http://www.addedbytes.com/download/css-cheat-sheet-v3.pdf/">PNG, 77Kb</a></li>
    </ul>
<div>

<div id="ttip">
Most computers will open PDF documents automatically, but you may need to 
download <a title="Link to Adobe website - opens in a new window"  
href="http://www.adobe.com/products/acrobat/readstep2.html" target="_blank">
                 Adobe Reader</a>.
</div>

大多数计算机会自动打开PDF文档,但您可能需要 下载。
或者作为
#maincontent
div之后的另一个div。是否可以使用jquery

编辑:

页面底部可以有一个或多个我想添加消息的PDF。我也需要IE 6的兼容性


编辑2:我不能也不想使用鼠标悬停在工具提示上

您可以遍历所有锚定标记,并使用jQuery查找该标记的扩展

但我认为这对你来说还不够。某些站点在向服务器发出请求时对文件进行流式处理。当发出这样的请求时,您将无法确定服务器将下载什么

例如,当我单击一个按钮时,会向服务器发出一个请求,服务器会按照以下方式处理该请求

Response.ContentType = "application/pdf";
Response.AppendHeader("Content-Disposition","attachment; filename=test.pdf");    
Response.TransmitFile("yourfilepath);
Response.Flush();
这将迫使浏览器打开一个对话框来保存或打开文档。

var tip=“大多数计算机将打开PDF文档”;
var tip = "<p>Most computers will open PDF documents ";
tip += "automatically, but you may";
tip += "need to download <a title='Link to Adobe website-opens in a new window'";
tip +=" href='http://www.adobe.com/products/acrobat/readstep2.html'  
               target='_blank'>Adobe Reader</a>.</p>";

$(document).ready(function(){

    //IF NUMBER OF PDF LINKS IS MORE THAN ZERO INSIDE DIV WITH ID maincontent
    //THEN THIS WILL PUT TIP PARAGRAPH AS LAST CHILD OF DIV
    if($("div#maincontent a[href*='/pdf']").length>0){
    $("div#maincontent").children(":last-child").after(tip);
    }
});
提示+=“自动,但您可以”; 提示+=“需要下载。

”; $(文档).ready(函数(){ //如果ID为maincontent的DIV中的PDF链接数大于零 //然后,这将把TIP段落作为DIV的最后一个子项 if($(($div#main content a[href*='/pdf'])。长度>0){ $(“div#maincontent”).children(“:last child”)。在(tip)之后; } });

检查它

我不想在PDF链接后添加为什么不将其添加为工具提示(格式很好)?我不想在悬停时显示此inf我想成为页面的一部分。我们可以在maincontent div后添加新内容,而不是在maincontent div中添加新内容吗?我已经编辑了答案!实际上,我担心它会多次添加提示段落,但jQuery比我聪明得多:(