views:

157

answers:

2

If page has .pdf files linked then a message in <p> should be add just before end of the #mainontent div as a last paragraph <p>

for example this is default html?

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

After detecting pdf

it should be like this

<div id="maincontent">
    <ul class="cheat_sheet_downloads">
    <li><a href="http://www.addedbytes.com/download/css-cheat-sheet-v2.pdf/"&gt;PDF, 316Kb</a></li>
    <li><a href="http://www.addedbytes.com/download/css-cheat-sheet-v3.pdf/"&gt;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 as another div after #maincontent div. Is it possible with jquery?

Edit:

Page can have one or more PDF i want to add message at bottom. and i need IE 6 compatibility too

Edit 2 : I can't and don't want to use mouse over tooltip

+1  A: 

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

But I don't think this will be enough for you. Some sites streams the files when a request is made to the server. You won't be able to determine what the server will download when such a request is made.

For example when I click on a button a request is made to the server and the server processes the request in the following manner.

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

This will force the browser to open a dialog box to either save or open the document.

rahul
+1  A: 
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

TheVillageIdiot
I dont want to add just after PDF link
metal-gear-solid
Yep that is the problem :(
TheVillageIdiot
Why don't you add this as a tooltip (a nicely formatted one)?
TheVillageIdiot
i dont want to givve this inf on hover i want to make a part of page
metal-gear-solid
can we add new <div> after maincontent div in place of new <p> in a maincontent div?
metal-gear-solid
I've edited answer! Actually I was afraid that it will add the prompt paragraph multiple times but jQuery is a lot intelligent than me :(
TheVillageIdiot
I want to add this PDF text after #maincontent div .can we add text a after specified #id
metal-gear-solid
i edited my question . see second code
metal-gear-solid
remember i don't want to add just after PDF page can have 2 or more PDF . i want to add message for PDF at the end of content
metal-gear-solid
i tested it's not working http://jsbin.com/ukuqa
metal-gear-solid
man you are using /pdf in href i was writing it for .pdf it is working now look at http://jsbin.com/oliho4
TheVillageIdiot
I tested ur latest code but it's not working see example here http://jsbin.com/epoba
metal-gear-solid
oh u r right sorry for inconvenience. now it's working fine i added wrong extension for pdf in question. going to correct .i need for.pdf not /pdf. . and i think i can change here a[href*='/pdf']" whatever i need. great thanks for this help
metal-gear-solid
one question why u r using <div. content</div> why dividing content in js in 3 line var tip = "<p>Most computers will open PDF documents ";.
metal-gear-solid
and i edited my question for /pdf to .pdf . you can change ur script accordingly
metal-gear-solid
i checked in IE 7 and it's giving error with ur example page. i found this link about error , see if it can help http://davidwalsh.name/internet-explorer-cannot-open-internet-site
metal-gear-solid
In sample the code is not wrapped in side `$(document).ready`. If you do it, then IE 7 won't complain.
TheVillageIdiot
@TheVillageIdiot - why it's not working if i add class to `<p class="red">` ?
metal-gear-solid