0

I have made a small web page in which I have some modal windows (jquery.simplemodal). When those windows are showed they should display two pdf files ( downloaded from server ).

<div id="modal1">  - hiden modal window
    <embed src="/FileDownload?id=100" width="100%" height="600px">
    <embed src="/FileDownload?id=150" width="100%" height="600px">
</div>

<table>
  <tr>
     <td>
        <a href="#" onclick="return activate(modal1)"> Modal Window 1</a>
     </td>
  </tr>
</tale>

The problem I have is that when the page is loaded also is downloading all files from server.

From HTML point of view I had read that nothing is possible to do to avoid this.

Can you please tell me if is posible to do that with Javascript ( for example updating src's embed element when the modal window is first displayed )?

On http://stackoverflow.com I have found some topics about changing the properties of an element but nothing is working on me.

JavaScript: Changing src-attribute of a embed-tag

Can i open a modal window from file A and displaying file B on the modal window?

Thank you!

P.S. This is an Intranet application. I want just to avoid downloading 20-40 files (a few MB each ) every time the page is open. The other solution I am thinking is to use a Java applet but I think this would complicate this small project.

Community
  • 1
  • 1
dan
  • 3
  • 4
  • 1
    javascript uses html to display the content, if it isn't possible with html, it also isn't possible with javascript. You might be able to embed it in a flash file somehow though. – Kevin B Feb 11 '14 at 20:09
  • Ah, your update makes an important change to the question. Yes, you can do that. All you need is a click event that changes the src of the embed (or replaces it entirely) that way the use clicks on a link to the pdf that they wish to view. – Kevin B Feb 11 '14 at 20:25
  • @Nucleon Some browsers (Chrome, maybe FF?) happily render at least simple PDF files. You can stick them in an `` on a page for those browsers. – Michael Feb 11 '14 at 20:37

3 Answers3

1

Using jQuery. I believe this is what you want to do: only load embed files if you click on the link which pops up the modal?

$("a").click( function (e) {
    e.preventDefault();
    $("#modal1").append("<embed id='100' src='/FileDownload?id=100' width='100%' height='600px'/><embed id='150' src='/FileDownload?id=100' width='100%' height='600px'/>");
    $("#modal1").show();
});

And the Fiddle

Fabricio
  • 839
  • 9
  • 17
  • 1
    Thank you. The example posted by you is working. I change it a little bit (to work only for some links and to insert data in other DIV's ) ... and of course is no longer working. Maybe if you have time you can point me on the right direction ( just reading now about JavaScript). Here is the code http://jsfiddle.net/M4v9v/ . – dan Feb 12 '14 at 20:46
  • Cheers mate. I'm not a specialist myself but by looking at the JavaScript console I could see the following error: `Uncaught ReferenceError: activateDiv is not defined`. I'm not sure why this is. I guess probably because activating jQuery in the fiddle makes it that all the code in the JS section will be placed inside a onLoad function: `$(window).load( function () {` **jQuery code goes here** `});` and then the function is only local inside this onLoad block and cannot be seen outside of it. But check this **[fiddle](http://jsfiddle.net/M4v9v/1/)**. – Fabricio Feb 12 '14 at 21:15
  • Thanks again. With your help I have discovered the errors: "No wraps - in body" and the missing of "#" when calling the function activateDiv. [final version fiddle](http://jsfiddle.net/XMAcX/) – dan Feb 13 '14 at 18:08
0

The nature of Web browsers is to download files to a cache so that upon the next visit, or during page changes, display times are greatly reduced. As a web developer there is nothing you can do to prevent this. The user can turn this feature off in his own browser if he desires to keep his cache clean, but you and your site cannot. There are ways to impede a viewer from intentionally downloading an image or file such as disabling right clicks over an image, but there are ways for a savvy user to get around these methods as well.

PDF files especially need to be downloaded to speed up viewing. If this is turned off, the user experience will be so slow you will drive people away from your site.

0

Even if its impossible to completely protect your files, there are a few ways to make it harder to download your original PDF document, we have a few PHP scripts that may help you that you can find inside our desktop publisher (available in GPL and commercial).

Its free to download and you can grab the scripts even if you don't use the rest of the product. If you download it and as you publish your document you can expand advanced settings and tick "sign and obfuscate" and you should get the scripts necessary to protect your files.

http://flexpaper.devaldi.com/flexpaper_flip_zine.jsp

FlowPaper Team
  • 500
  • 3
  • 7