I got a webpage where members can download different kind of files on. I wan't to get information about which files and how many times each member have downloaded. when the user want to download a file he get browser pop-up where he gets 3 choises: "Open", "save" and "Cancel".(file dialog box in browser). i want to update the download status only if open/save button is clicked
Is there a way to detect which button was clicked on "save/open/cancel" dialog?
You can't know that. Some browsers even start the download before the user decides what to do with the file. But perhaps you can get your webserver to log if the download has been completed. That's probably the most reliable result you can get.
There is no way to know which button was clicked.
I dont think you can. The site just streams the file to the browser. What the user does
with the file is not known by the website as there is no more server side
interaction.
Related
Ok so this is a general question about browser interaction and HTTP mechanims
Here is the scenario
There is a very rich interface with a lot of buttons.
The user clicks the button "generate the report"
Then there is a loading time of approximately 15 seconds and then the "save file" dialogue box appears
The user saves the files wherever he wishes and do further stuff.
Now I want to:
Prevent him from interacting with the interface during step 3.
At the end of step 3, trigger some specific javascript like showing a popup.
All this actually sums up to "how to detect the appearance of the download dialog box in javascript" because once this one is solved, this is easy to set up some mask during the file generation, and to do whatever is required once the event has been detected.
Unfortunately it seems like there is no way to launch a file download via Ajax because it lacks adequate handling for turning an XMLHttpRequest into a save as dialog box. As a consequence you need to submit some form, but the mechanism is a little weird because although you submitted the form absolutely nothing happens in the DOM. Then the browser detects that response to the form submission is an incoming file and shows a download box instead of trying to display the file content, and once the user is done with the download box, the browser somehow manage to restore the interface in its previous state so that the user can keep on browsing (or at least this is how I understand the thing).
Display a loading sign for x seconds, disable click events (see here) or replace them with a dialog saying they should stay quiet while it loads. Do not forget to make the loading sign moving/showing progress or they will get bored. I'm sure there are plenty of libraries to achieve this, you could even try using the <'progress'> tag. As #j3r3m7 said, if they want to close the browser they will; the goal here is to make user understand he has to wait for x seconds and make him eager to wait.
As for your other issue, please look here
EDIT : A helpful plugin to address these kinds of issues can be found here.
Interesting question as in essence you can't stop the user from doing anything really... they could if so inclinded:
close their browser
enter a url directly to go to a new page
click back in the browser
open a new browser window and navigate to the report generation page for a second time
refresh the page
So, if you have a long running process quite a good way to deal with it is:
indicate that the process may take a while
at the point that the report is ready provide a unique link to the generated report
if you are using a javascript framework like AngularJS you could asynchronously handle an event that shows a report download/view link when the report is ready.
I'm pretty sure this isn't possible but thought I'd check with you guys.
I've just had a bizarre query from a client who wants to know if it's possible to give the user the option to either download a pdf or open it in their browser.
They have a thumbnail for the PDF. Single click to open it in the browser or double click to download it. I know I can catch the single or double click with jQuery. I just want to know if it's possible to force the behaviour of the link.
Thanks
This is possible, if for example you are using PHP you can create 2 methods, once will be a simple direct link to the pdf file (if a customer has adobe reader then it will open the pdf in the browser otherwise it will force a download), the other method would always force a download.
You can find a PHP force file download example here: How to force download of a file?
I have a web page with few tabs. All tabs have same data but in different format. The page has a copy to clipboard feature which copies the contents of the active tab to clipboard. Similarly we need to have a save as text file option which copies contents of the active tab alone by prompting use for selecting a location and then ssving it.
I checked a few alternatives like use of execcommand, but not sure whats best way to do the same.
Thanks in advance.
You could accomplish this by posting the contents to a server page which would basically echo the contents back in such a way as to provoke the browser into launching a "what do you want to do with this?" dialog where one option is "Save to disk." If there's a way to get the client to go straight to the "Save to disk" option, all the better.
I've found that different browsers deal with this in different ways - some look at the extension of the server page, and some at the HTTP content-type.
For example, I had a page, call it server.cgi, which would produce a zip file and I think IE defaulted the file name in the "Save As" dialog to server.cgi. By changing the server file to server.zip, the prompt did the right thing. I think Firefox responded to the content-type header.
In javascript, how can I detect when the browser brings up the open/save/cancel prompt when loading a file?
If possible, is it the same for all browsers?
I'm trying to fix a problem with users clicking a download button, being impatient and clicking it again, and again which is taxing our servers. I tried just hiding the button while the file is processed, but the icon will come back before the open/save/cancel prompt shows up.
The code goes something like this:
...
users clicks button,
button hides,
external process gets the file,
button appears ...
You can't.
How the browser deals with a requested resource - open it, start an external application, offer a "save" dialog - is outside of what you can control using JavaScript.
You can't! No way, that's it!
When user clicks on a hyperlink, i am opening a popup window which downloads a file. Post download, it shows open/save dialog box. I want to close the popup window once the download is done (when user is prompted for saving the file).
I have tried window.close method, but it doesnt work as the context is not the popup window but the open/save dialog box.
I think you can not control it programatically. This is browser-specific thing where some browsers allow you to tick on a check box to close the window and so on.
you can do one thing:
after the "file writing code in your servlet or struts action use"
Step 1: call "response.flushBuffer();"
Step 2: call response.sendRedirect("close.htm")
where close.htm is :
<html>
<script>
window.close();
</script>
</html>
Only problem is identifying if the download is complete. I don't think there is a possible way of doing that. Anyway is there any use of keeping the pop-up open untill the download is complete. You can simply close the pop-up once the download is initiated. Using below JavaScript, can't you?
pop_up= window.open("", "PopUpName");
pop_up.document.write('POPUP TEXT');
pop_up.close();
Browsers have a habit of deciding for themselves whether to try to download a file or open it inside the browser window, depending on the browser used, plug-ins and server settings. It sounds like you might be opening the link in a new window, as if the browser was going to open the file rather than download it, and then the browser has opted for the download. This leaves the user with a downloaded file and a blank window that you have no control over.
To force it to download, you should be able to set the Content-Type header for the target of the link to application/force-download. How you do this will depend on your setup, and whether the file is downloaded directly (in which case it will be a server setting) or via PHP or .Net (in which case it's easy to programmatically set the header). Also make sure that the hyperlink doesn't have a target="_blank" attribute that opens the link in a new window.
It's Browser functionality, You can change browser setting for that. You shouldn't go for programming . By default If you will download file in firefox it ask for saving, but in crome It's doesn't ask.
You need to change setting of your browser.