Using html5 download attribute, is it possible to detect when the file has actually been downloaded? Some browsers offer prompt box, and the user can click cancel instead, while other browsers automatically start download by clicking on the link.
<a href="path/to/file" download >download here</a>
I need to count number of downloads, if its not possible this way, is there other option?
The way you want to do this is not possible. You don't want to count with the client side, rather the server side. The way you could do this is whenever the server finishes a download, you could add one to your counter. An easy (but there are better ways) of doing this would be to create something like a downloadhandler.php where it would tally a download every time you loaded it, and echo something like:
<html><head><meta http-equiv="refresh" content="5;url=your-download-url"></head></html>, to redirect you to the download URL.
Related
I am trying to automate downloading images from a site, and I am trying to use casperjs (1.1.4) and phantomjs (2.1.3) to do this
Doing this manually, I visit the site with a browser, log in, navigate to the desired images, select each, and then click a Download button. This then brings up the usual dialog for saving files.
In my code, I have figured out how to get as far as the download in my casperjs/phantomjs script, but I cannot successfully download an image using the casper.download() function. When I hover over the Download button, the URLs have this form:
https://www.frustrating.net/image/download?uri=https://frustrating.net/repo:/0495/4:1:8Q9MCSN3
But passing this URL (or even just the part after uri=) fails because casperjs says that it cannot handle cross-domain ajax requests.
In searching for answers, I find that many people have reported a problem more or less like this one, but there's no general solution.
Apparently, in recent versions of casperjs, there is a sendAjax() function, but it isn't clear to me how one gathers the information required by that function from the website that one is using, or even whether that function is what should be used in a situation like this.
How do I troubleshoot this? What information do I need to know in order to make casperjs download images from such a site? Since I'm learning javascript, I would ideally like to see some commented code that I could follow and modify as necessary. I can use Firefox's InspectElement feature to get more information, but it isn't clear to me what information I need.
I want to try to see how much faster a website can load on a server, without having to copy the entire site over first. I have an idea of how I can do that, but I'm not sure if I'm overlooking something, and I'm not sure the best way to do what I am trying to do.
If I use a website like Pingdom, I can see the number of files that are loaded for a given URL, and the size of each of those files.
I want to create a page in PHP that can simulate the loading of these files. I assume I can do this by calling a file on my server that can generate files with a size I specify. So, for example, I could call this file more than once, with a file size appended in the query string, and the browser would download those files.
Maybe I can generate images on the fly that will be the file size I specify?
Would this idea work, or is there something I'm overlooking?
If this is possible, how would I generate these files?
I'm not sure if it's exactly what you are looking for, but in Google Chrome there is an option to simulate a connection speed. When you open the developer tools, you can go in the Network tab and to the right of "Disable cache" you will see "No throttling" which is a drop-down and you can select the internet speed you want to simulate.
I am using HTML and CSS, and willing to use a very simple JavaScript code if necessary.
I uploaded ResumeWord.doc and ResumePDF.pdf to the FTP. I created links for "View" "Download" and "Print" for each. ResumeWord.doc only seems to give me a pop-up with options to Open or Save instead of opening in the browser, while I was able to open ResumePDF.pdf in the browser but not create a clickable link to download it without viewing. I have tried the HTML target_blank and JavaScript window.open for the "View", unsuccessfully. I am self-taught and an amatuer.
How can I make the "View" link open ResumeWord.pdf in the browser without a pop-up?
How can I get ResumePDF.pdf to download when the user clicks "Download"?
Without some help, the browser won't assume that a user has Microsoft Word installed on their computer. That is why you only get the option to save it, rather than it opening.
The PDF, however, is something that can be viewed in-browser, and the browser can check if the right files are installed to make this happen. So if they are, the browser goes ahead and opens the file.
As for forcing the browser to open a word file, see this SO question.
And as for forcing a download of a PDF, see this SO question. It may not be possible, in your case, as the solution involves sending different server-side headers.
could anyone please give me an example on how to force to show the save box using ActiveXObject("WScript.Shell"), without php or other stuff !?
i would like to allow to download some mp3 file, instead those are being opened directly in the windows media player..
i just want to give the user the chance to choose whether download them or just open them
thanks a lot in advance
You need to use the Content-Disposition HTTP header in your web page. It's the cross-browser supported method for forcing a SaveAs dialog to appear.
http://www.jtricks.com/bits/content_disposition.html
Aims
I'm trying to let users download a file (myfile.zip in this case) by clicking a button on the page, without them leaving the page - ie the browser must stay on the current page, and leave them in a position where they can continue to use the page, including clicking the button again (should they wish to get a new copy of the file).
I need this to work across all browsers (IE6-8, Firefox, Chrome, Opera, Safari).
Background
Packaged inside the zip is a selection of stuff based on their other interactions (some of which may be partially complete) from the same page (this is all done via ajax) and I don't want them to leave the page as they would lose any unsaved changes.
Add the following header when the download file is served:
Content-disposition: attachment; filename=filename.zip
Most browsers will wait to see what type of thing they are loading before they clear the current page, and if it something that should be downloaded as a file they won't navigate away from the current page (they'll show a Save As dialog in front of the page, which can be dismissed to return to the page).
If however you find that a certain browser does navigate away from the current page, you may try having the link to the download contained in a small iframe, so only that frame changes.
I think it's a better solution to opening the link in a new window, because some browsers will leave the new window up even once it's determined that it is a file that should be downloaded, so you end up with a blank window.
If you make the link open in a new window/tab (e.g. via the <a> tag's target="_blank" attribute), it won't disturb the contents of the current window.
The target attribute is deprecated, but widely supported. Depending on the browser, you may also be able to use the CSS3 target-name property.
If your goal is to absolutely guarantee that the main window is undisturbed, this is likely the safest method, as it's resilient against download errors.
To avoid leaving the page (if you do this the page tries to close itself first, so that it's sure that you've saved everything, and you get warning messages if you haven't) or leaving blank tabs (which I don't like, nor the use of the depreciated target attribute) I've used an iframe, whose src attribute is changed in javascript.
This works everywhere except some versions of Opera, which I have considered an acceptable loss (I might fix that via the use of one of the other solutions plus browser detection later).
I believe if you direct the user to a file and the MIME type is something the browser knows it must download vs render, the browser will not leave the page. For instance if you were serving a zip file the browser would know it was a zip file and prompt for download. But if you were going to serve a zip file from a page request (i.e. /file.aspx?file=myinfo.zip) then file.aspx would need to change the MIME type to be "application/zip" before send back the response in order to prompt the user for the download.
One major caveat here is if the file didn't exist for some reason the user would get a 404 and be directed to the error page.
As a sure-fire way of not redirecting the user you could open a pop-up for downloading.
We do this on postback on an aspx page by setting ContentType to "application/octet-stream", then streaming the zipfile with Response.BinaryWrite(..) and Response.Flush().
Gives the user a popup "do you want to open or save" the file.
Page is still available.
By the way, specifying the appropriate content disposition header alone might not work in all browsers. Specifically, I've seen it not work in Opera, and IE7 displays the yellow security warning bar.
In addition to the appropriate header, as described by thomasrutter, The way I've done this is by using a hidden form:
<form id="download_form" method="get" action=""></form>
When the user clicks a button, you can manipulate the "action" attribute of the form with the URL of the file.
This seems to work in all browsers, even IE7!