Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

JS: preload a PDF file AFTER current page and images complete loading/displaying

Posted on 2009-12-16
4
Medium Priority
?
1,485 Views
Last Modified: 2012-05-08
I have a database catalog page dipslay situation where we have a large jpeg image (~100K) that is by default showing as the main element of the page.
Then we have a PDF (for more clarity or enlargement) (some are 500K in size)  that can be displayed (using a JS script) upon click of an ENLARGE/DETAIL button.
What (html or JS) code can i put in to have the PDF be preloaded, but ONLY AFTER the main image completes?  A strategy of a simple time delay is fine if there's no JS mechanism to wait-for-page-display-completion.
By having the PDF "in the wings"  then it would display quickly once called upon.

thanks
0
Comment
Question by:willsherwood
  • 2
4 Comments
 
LVL 75

Accepted Solution

by:
Michel Plungjan earned 1000 total points
ID: 26078233
Try this. I exclude mac since it will load the pdf externally
I assume the jpg is called exactly the same as the pdf

<html>
<head>
<script type="text/javascript">
function loadPdf(img) {
  window.if1.location=img.src.replace('.jpg','.pdf');
}
</script>
</head>
<body>
<img src="bigimage1.jpg" onload="loadPdf(this)" />
<iframe style="display:none" width="1" height="1"></iframe>
</body>
</html>

Open in new window

0
 
LVL 9

Assisted Solution

by:experts1
experts1 earned 1000 total points
ID: 26078578
willsherwood,

The code below does as follows:

(1) Use an image object to pre-load a PDF file
(2) Begin to pre-load PDF file and render button object, after document is fully loaded
(3) Allows user to view PDF file after popup message

<html><head><title>PreLoad_PDF</title>
<SCRIPT language=JavaScript type=text/javascript>
var image1 = new Image();  //Define image object to pre-load file
var btPDF;
btnPDF = "<INPUT type='button' value='<View PDF File>' ";
btnPDF = btnPDF + "name ='button1' onClick='view_pdf();'>";

function load_pdf() 
{
//This function pre-loads pdf file after original document is loaded
image1.src = "Your_PDF_File.pdf" //Your PDF URL Goes Here
//Display button to view PDF file
document.getElementById("pdf_view").innerHTML = btnPDF;
}

function view_pdf()
{
alert("You Are About To View A PDF File")
window.location.href =image1.src  //View the preloaded
}
</SCRIPT></head>
<body onload="load_pdf();"> 
Original Web Page
<br>
Blah....!
<br>
Blah...!
<br>
Blah...!
<br>
Etc...!
<br>
<br>
<div name="pdf_view" id="pdf_view">

</div>
</body>
</html>

Open in new window

0
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 26078715

willsherwood wanted the PDF to begin preloading after the big image had finished loading
Also I did not make any assumptions on where the ENLARGE button would show the pdf
0
 

Author Closing Comment

by:willsherwood
ID: 31666912
oh my what great responses!  THANK YOU.
much appreciated.
(correct, PDF after main page, so it wouldn't compete)
thanks!!
0

Featured Post

Prep for the ITIL® Foundation Certification Exam

December’s Course of the Month is now available! Enroll to learn ITIL® Foundation best practices for delivering IT services effectively and efficiently.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Having worked on larger scale sites, we found out that you are bound to look at more scalable solutions to integrating widgets, code snippets or complete applications and mesh them into functional sites, in any given composition. To share some of…
This article discusses how to create an extensible mechanism for linked drop downs.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses

810 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question