How to detect linked PDF on a page and show a message to download Adobe Reader using jquery?

If there are .pdf files on the page, then the message in the <p> should be added immediately before the end of the #mainontent div as the last paragraph of the <p>

For example, is this the default 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> 

After detecting pdf

he should be like that

 <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> 

or like another div after the #maincontent div. Is it possible using jquery?

Edit:

A page can have one or more PDFs that I want to add to the bottom of the message. and I also need compatibility with IE 6

Edit 2: I cannot and do not want to use the mouse over the tooltip

+2
source share
2 answers
 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 here

+1
source

You can iterate through all the anchor tags and find the extension using jQuery.

But I do not think that this will be enough for you. Some sites transfer files when a request arrives at the server. You will not be able to determine what the server will load when performing such a request.

For example, when I click the button, a request is made to the server, and the server processes the request as follows.

 Response.ContentType = "application/pdf"; Response.AppendHeader("Content-Disposition","attachment; filename=test.pdf"); Response.TransmitFile("yourfilepath); Response.Flush(); 

This causes the browser to open a dialog box to save or open the document.

+1
source

Source: https://habr.com/ru/post/1310027/


All Articles