2

I have a link in my JSP page, where the user uses it for downloading an Excel File. When the user clicks on the link, the controller goes to a java script function where I display a moving image(like progress bar) and then it will be redirected to Action Classes. After executing the java code, a pop up window appears asking the user to open/save the file. As the page is not getting refreshed, the progress bar keeps on running and I am not able to hide it.

Does anyone have an idea how to resolve this using Javascript as I dont have much idea on Jquery.

Thanks in advance.

function generateRnDFootPrint(){ 

progressBar.showBar();     // progress bar appears 

location.href='<%= contextPath %>/saveMTP.do?method=getRnDFootPrintReport&orgCode=<%=orgCode%>&orgId=<%=orgId%>'; 

}
Pointy
  • 405,095
  • 59
  • 585
  • 614
Sanjay
  • 91
  • 1
  • 1
  • 10
  • 1
    Show me your javascript function, please – Hackerman Mar 05 '13 at 16:04
  • the progress bar should disappear once the download starts? Is that what you wants? – kaysush Mar 05 '13 at 16:04
  • @Suku Yes. progress bar need to be disappeared once the file is completely downloaded. – Sanjay Mar 05 '13 at 16:06
  • 1
    No you are not getting my point. By the description you gave me the downloading of file starts when you click the link and there is no way to know that download completed or not. What i said is that once download starts then bar should disappear. – kaysush Mar 05 '13 at 16:09
  • @Suku yea. I got it now. When a user clicks on the link, it takes some time to start downloading. During that time I need to show the progress bar. Is that possible? – Sanjay Mar 05 '13 at 16:13
  • So you want to make it look like an ajax file download request? – Luiggi Mendoza Mar 05 '13 at 16:14
  • location = ''; at the end of the js ?? – Hackerman Mar 05 '13 at 16:15
  • @Robert yes. I am not sure I understand your question. – Sanjay Mar 05 '13 at 16:19
  • You have a js function, and that function is triggered when the user click on the link, right?? – Hackerman Mar 05 '13 at 16:27
  • @Robert yes. exactly.. – Sanjay Mar 05 '13 at 16:31
  • can you post that function.....the code....in that way i can add the code to reload the page on the end of the js code xD – Hackerman Mar 05 '13 at 16:36
  • @Robert when the user clicks on link, it calls this function and thats the only code it contains. When it comes to location.href, it goes to java code and gets response.setHeader("Content-Disposition", "attachment; filename="+reportName); If you still need more info, plz let me know. Thanks. – Sanjay Mar 05 '13 at 16:43

2 Answers2

0

What you can do is give an id to the download link

<a id="download-link" href="your_value_here">Download Link</a>

In JavaScript

var link=document.getElementById("download-link");
link.onclick=function(){
  progressbar.hide();
}

And if you want jQuery version

$("#download-link").click(function(){
   progressbar.hide();
});
kaysush
  • 4,797
  • 3
  • 27
  • 47
  • Thanks for your suggestion. But I think I am not making it clear. The user clicks on the link – Sanjay Mar 05 '13 at 16:22
  • @Sanjay thats what i have done, when user clicks on the link progress bar disappears. – kaysush Mar 05 '13 at 16:25
  • Thanks for your suggestion. But I think I am not making it clear. 1. The user clicks on the link 2. Progress bar should appear 3. It takes 60-70 secs to start downloading and I need to show the bar during those 70 secs. 4. Once the file starts downloading, at this point I need to hide the bar. – Sanjay Mar 05 '13 at 16:25
  • @Sanjay but those 60-70 seconds are not in your hand. It may take more time also and it may take less time too. That totally depends on browser. What you can detect using JavaScript is that when does user click on the link. By the way can you give me some example site where this sort of functionality is there so that i can make it more clear to you. – kaysush Mar 05 '13 at 16:28
  • my question is somewhat related like this http://stackoverflow.com/questions/1106377/detect-when-browser-receives-file-download I could not understand the solution as they have discussed in Ajax, Iframes. Thanks for your help. – Sanjay Mar 05 '13 at 16:39
  • @Rubert yes. I have popup box asking me to save/open the file. I have tried to hide the bar getting the focus of the window. But the problem comes, if the client browser has a setting to download automatically in a particular path then he wont be getting any popup and hence the progress bar goes on and on.. – Sanjay Mar 05 '13 at 16:51
0

Try the following....i just add a line at the end of the function:

function generateRnDFootPrint(){ 

progressBar.showBar();     // progress bar appears 

location.href='<%= contextPath %>/saveMTP.do?method=getRnDFootPrintReport&orgCode=<%=orgCode%>&orgId=<%=orgId%>'; 

setTimeout(function(){progressBar.hideBar();},2000);


}

I hope it does the trick.....in the case it does not, then you should have a function that hide the bar and call it, like in the commented line ;)

Saludos.

Hackerman
  • 12,139
  • 2
  • 34
  • 45
  • Thanks Robert. I have the function exactly progressbar.hideBar(); But when I add that at the end, what happening is progress bar appears and then immediately it disappears and then it goes to the java code and the remaining process continues. – Sanjay Mar 05 '13 at 16:57
  • Wow..!! Cool idea. It may not be the exact answer. But I think it will help me.. I will check out and let u know.. Thanks a lot.. :D – Sanjay Mar 05 '13 at 17:09
  • Yes Rubert. It works for me. Report will be taking around 60-70 seconds to start downloading. So I have set 70 seconds timeout. When the file is downloading, progress bar disappears. Thats simple and easy solution..! :D – Sanjay Mar 05 '13 at 17:44
  • I glad to help @Sanjay, feel free to ask, whenever you want ;) ....you missed the upvote xD – Hackerman Mar 05 '13 at 18:21