Download a pdf (not open in tab) in Javascript - javascript

I have a landing page on which there is a form which is filled by user and then it goes to a thank you page (which is another page). On thank you page I simply want to prompt the user for saving a pdf as the thank you page loads. Please note I want the file to be saved/downloaded and not opened on the same tab or another tab in the browser. I have tried multiple solutions but they all seem to open the pdf in the browser itself and not download it. Some of the methods I have tried are meta tag download, page redirect download, iframe download but they all open the pdf in browser itself and not download it. I just want a simple solution for downloading the file and not opening it in the browser. Also the pdf should download automatically without clicking any link or button.

The document.ready event of the thank you page should trigger a local script that runs a server script to download the PDF. Be sure to set the headers as described above. If you try to link directly to the PDF, it'll try to load in the browser.
Alternatively, you could create the PDF in a directory that is already set to only download files by setting the .htaccess file for that directory.

Related

All downloads from iframe go to folder in server

My website contains a iframe which allows the user to navigate the web. If the user clicks a download button on any website I would like it to download in a folder located on the servers itself. So if the user presses download on a image, the image is downloaded onto a folder on the server instead of the computer. Is this possible? I have no idea on how to go about doing this.
You seem to need to display a download button on any website...
You cannot modify all internet websites with your code.
The only way to go this is :
to create a browser extension, like this one : https://chrome.google.com/webstore/detail/image-downloader/cnpniohnfphhjihaiiggeabnkjhpaldj
This extension will be able to interact with any website and do what you want.
or (more simple to code) execute a Javascript of your own that will make floating a download button on any image of any website.
You can do this with this Chrome extension for example : https://chrome.google.com/webstore/detail/custom-javascript-for-web/poakhlngfciodnhlhhgnaaelnpjljija
You can also use a "download" button over the iframe that launch a curl Linux command that will download the iframe page and all the images, files etc...

Image button - print a document from my webpage

I have a website, but I need a button which I want to print a specific .pdf file from my webpage database.
As an example, this site
has a print button, which gives you option to print some pdf files
Any idea how can I do that?
I've tried this one, but it's not working:
<a href="../Documents/ScrittoGraffito/Scritto_Customers/Nicolaides_Optical/Nicolaides_webpage/Shop1_Banner.pdf"
onclick="window.print()"/><p class="test">link</p></a>
That code will tell the browser to open the print dialog for the current page.
If you want to force the browser to print the linked pdf then that is not possible, as it will be completely controlled by the application or plugin that handles pdf documents.
EDIT;
Apparently it is possible, but you have to make use of a pdf toolkit.

Is it possible not to allow iframe to show file download popup?

I have a code like:
<iframe src="http://www.upnp.org/download/UPNP_understandingUPNP.doc"></iframe>
When this code is rendered, browser file download prompt is shown to user. I'd want to prohibit iframe from showing this download popup.
Is it possible?
I'd want it as iframe's url is controlled by users, not site owner.
No.
The server hosting the URL can decide if it wants to mark it as an attachment (suggesting that the browser to save it) or inline (suggesting that the browser should open it; using a plugin if one is available).
The browser decides how to handle it.
The page linking to it (even if it does so via an iframe) has no control over any of the above.
To avoid the download popup, you could use ajax instead of an iframe to load the url.

Javascript to Load and Save Files Temporarily

I am working on a thing where I have an iframe. I want to load a static javascript file to this iframe every time user clicks on a button. The javascript file is located at the server and because this is the static file so I would like it to be downloaded to the client once and every time user clicks on the button it just loads this file into iframe without calling server.
I know AJAX can be used to download this file contents and how to add script tag to the iframe but I am not sure where should I temporarily save the contents and then put the contents back into a file to put that file as script tag into iframe.
You can consider this fiddle.
Have you considered just dumping the data into a cookie?

iFrame file upload with IE produces download dialogue

I'm developing a custom module for Drupal dealing with Document Management. At this point, the module loads, you can upload files (via a hidden iframe and some ajax requests), browse directories and set various levels of permissions. And everything works perfectly in Firefox.
Issue:
In IE however, I run into an issue. For some reason when I upload a file the save file dialogue pops up and asks me to download the file I just uploaded. It looks like it's asking me to download it from the web-servers tmp location however, as that seems to be the file-name and such. However, if I hit cancel and refresh the page I can see that the file I uploaded did actually get uploaded to the server.
Here is how the upload process works. Click the upload button. The upload button is the standard file input form element hidden and placed over a styled version of the button. Clicking on this causes the "Choose a file" dialogue to open.
Select a file and click "Open". A modal dialogue pops up asking you for some further information about the file. The modal is part of the same form element but remains invisible until you click Upload button
Clicking save in the modal causes the file to be uploaded. The "action" attribute on the form is pointed to a page and the target is the iframe.
The iFrame is polled a few times every second to see if it's contents have changed. When the file is uploaded a "success" message appears in the iframe. Since it belongs to the same domain, I scrape the content within the iframe.
Once the iFrame says that the file has been uploaded, I use some JS to update the application with the name of the file
Since I can't use Firebug in IE, I have to stick to utilizing Microsofts Web Developer Toolbar, which makes it very hard to figure out if the bolded step is actually occuring. It seems like it should, since the file IS being uploaded. It is just getting interrupted by that file download dialogue.
Since no one seems to have an answer, I'll post the fix I found. I doubt it's perfect, but it's the best solution I could come up with.
It turned out to be an issue with the polling as suspected. The fix ended up being instead of outputting json to the iFrame, just output some JavaScript that calls a function that updates the main window. That simple.

Categories

Resources