callback function for location.href

User

We have below code

Javascript:

function Download() {
            //Show Loading Spinner
            location.href = "FileDownloadHandler.ashx";              
            //Some Code(Hiding Loading Spinner)
        }

aspx page:

<input type="button" value="Download" onclick="Download();" />

"FileDownloadHandler" will download the file to the user.

Actual Result: Code below location.href is executing immediately without completion of handler execution.

Expected Result: I want to stop executing "SomeCode" until handler completes the execution.

How can I achieve this?

Thanks in advance.

User

Finally I found a solution to my problem. Using jQuery plugin we can achieve this. I have implemented it and working like a charm.

This Plugin does file download and it has successs & failure callbacks, so we can have control on the code which should execute after completion of file download.

Here instead of location.href, we have to call this plugin to invoke our FileDownloadHandler as below.

 $("#loading").show();

 $.fileDownload('FileDownloadHandler.ashx', {

                successCallback: function (url) {

                    $("#loading").hide();

                },
                failCallback: function (html, url) {

                    $("#loading").hide();
                    alert("Failed");

                }
            });

More details below

http://johnculviner.com/jquery-file-download-plugin-for-ajax-like-feature-rich-file-downloads/

http://jqueryfiledownload.apphb.com/

http://github.com/johnculviner/jquery.fileDownload/blob/master/src/Scripts/jquery.fileDownload.js

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

String is not a function on window location href

From Dev

Variable from function into window.location.href 'not defined'

From Dev

Function to get href of link at mouse location/on hover (Something similar to Copy Link Location in Chromium)

From Dev

Function to get href of link at mouse location/on hover (Something similar to Copy Link Location in Chromium)

From Dev

Callback for location update

From Dev

location.href not working

From Dev

location.href is undefined

From Dev

location href returns as undefined

From Dev

callback = callback || function() {};

From Dev

how to set both the href and title attributes and give it a callback function at the same time?

From Dev

how to set both the href and title attributes and give it a callback function at the same time?

From Dev

Function with a callback

From Dev

When I use window.location.href ,then my another function not calling .Following is my javascript code

From Dev

call page function from firefox addon with location.href doesn't work

From Dev

location.href is decoding the URL

From Dev

location.href with a jquery handler

From Dev

window.location.href not working

From Dev

html href not linking to correct location

From Dev

Better solution to location.href

From Dev

if confirm ignores location.href

From Dev

Preventing href until gelocation captured (callback help)

From Dev

changing a tag href depends on window.location.href

From Dev

Callback function C++

From Dev

Callback function in Swift 2.0

From Dev

JavaScript Multiple Callback Function

From Dev

Pass callback function to directive

From Java

callback function not executes unexpectedly

From Dev

Extjs callback function to controller

From Dev

WPF Animation Callback Function

Related Related

  1. 1

    String is not a function on window location href

  2. 2

    Variable from function into window.location.href 'not defined'

  3. 3

    Function to get href of link at mouse location/on hover (Something similar to Copy Link Location in Chromium)

  4. 4

    Function to get href of link at mouse location/on hover (Something similar to Copy Link Location in Chromium)

  5. 5

    Callback for location update

  6. 6

    location.href not working

  7. 7

    location.href is undefined

  8. 8

    location href returns as undefined

  9. 9

    callback = callback || function() {};

  10. 10

    how to set both the href and title attributes and give it a callback function at the same time?

  11. 11

    how to set both the href and title attributes and give it a callback function at the same time?

  12. 12

    Function with a callback

  13. 13

    When I use window.location.href ,then my another function not calling .Following is my javascript code

  14. 14

    call page function from firefox addon with location.href doesn't work

  15. 15

    location.href is decoding the URL

  16. 16

    location.href with a jquery handler

  17. 17

    window.location.href not working

  18. 18

    html href not linking to correct location

  19. 19

    Better solution to location.href

  20. 20

    if confirm ignores location.href

  21. 21

    Preventing href until gelocation captured (callback help)

  22. 22

    changing a tag href depends on window.location.href

  23. 23

    Callback function C++

  24. 24

    Callback function in Swift 2.0

  25. 25

    JavaScript Multiple Callback Function

  26. 26

    Pass callback function to directive

  27. 27

    callback function not executes unexpectedly

  28. 28

    Extjs callback function to controller

  29. 29

    WPF Animation Callback Function

HotTag

Archive