0

Folks,

I have a web page that requests the user enter a start date and an end date. We call this the 'date select' page. The user clicks submit, the dates are sent to the server, and the server creates then downloads a spreadsheet. This works fine. Except for the fact that since this is a download, the web page stays on the 'date select' page. Is there a way to get the page to forward to a different page after submit is clicked?

I hope this explains the situation correctly. I haven't been able to find anything that describes this online.

Thanks!

1 Answers1

0

Try redirecting the form to a new tab then redirecting with javascript

The main issue is that the form submission (but not necessarily the file download itself) has to complete before the redirect otherwise it gets lost. The simplest way is to use a timeout:

<form target='_blank' id=myform method=post action="/generatexls">
...
</form>
<script>
    //uses jQuery
    $('#myform').submit(function(){
        setTimeout(function(){
            location.href='/newpage.htm'
        },100)
    })

</script>

I have just checked this on my system: IE11 and Chrome 36 both immediately close the new tab as soon as they realise that it will not have any content in it. Some browsers may obviously continue to display a blank tab or window. Another option is to target the form to an iframe on the same page, but this needs a longer timeout to be safe

There is a more complicated solution using cookies which may be of interest here: Detect when browser receives file download

Community
  • 1
  • 1
Danny
  • 144
  • 3