如果页面链接了.pdf文件,则<p>中的消息应作为最后一段<p>添加到#mainontent 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>或者作为#maincontent div之后的另一个div。使用jquery可以吗?
编辑:
页面可以有一个或多个PDF我想在底部添加消息。我还需要与IE6兼容
编辑2:我不能也不想在工具提示上使用鼠标
发布于 2009-12-14 17:44:44
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);
}
});check it here
发布于 2009-12-14 17:41:47
您可以遍历所有的锚标记,并使用jQuery找到它的扩展。
但我不认为这对你来说是足够的。一些站点在向服务器发出请求时流式传输文件。当发出这样的请求时,您将无法确定服务器将下载的内容。
例如,当我单击一个按钮时,会向服务器发出一个请求,服务器会按以下方式处理该请求。
Response.ContentType = "application/pdf";
Response.AppendHeader("Content-Disposition","attachment; filename=test.pdf");
Response.TransmitFile("yourfilepath);
Response.Flush();这将强制浏览器打开一个对话框来保存或打开文档。
https://stackoverflow.com/questions/1899913
复制相似问题