Click to See Complete Forum and Search --> : scan page, modify path, open in a new window


litbynature
08-23-2005, 11:52 AM
Hi....

Thank you in advance for your patience/time. I am new to this stuff.

I want to create a function [in the footer] of my web pages that scans the pages for PDF files, translate the path, and open it to a new window.

for example...

when a user clicks on a PDF link....

i would like a function to translate the path [through a decision statement] to decipher between a testing server and a live server path, then open the PDF in a new window.

is this possible???

an awesome webdeveloper.com member sent me this about a week ago. on the right track, but i could not build off of this. it might help you.

onload=function()
{
var links=document.getElementsByTagName("A"), pdfs=[], i=0, e;
while (e=links[i++])
if ((e=e.href).indexOf(".pdf")+4==e.length)
pdfs.push(e);

alert(pdfs);
}

THANK YOU FOR ALL OF YOUR HELP!!!!!
michel

Mr J
08-23-2005, 03:11 PM
Is there going to be more than 1 link to pdf files in a page

litbynature
08-23-2005, 03:13 PM
yes, unfortunately. :) hehehe.

there will be more than one pdf link on a page.....

Mr J
08-23-2005, 03:30 PM
This will open PDF files in a new window while opening html files in the curent window

<script type="text/javascript">
<!--

function chk_url(isFile){

if(isFile.indexOf(".pdf")!=-1){
window.open(isFile)
return false
}

}

//-->
</script>

<a href="file1.pdf" onclick="return chk_url(this.href)">PDF</a>
<a href="file2.htm" onclick="return chk_url(this.href)">HTML</a>

When you say

testing server and a live server path

do you mean like online or offline?

If so take a look at this little script

www.huntingground.freeserve.co.uk/scripts/online_offline.htm