Results 1 to 2 of 2

Thread: Problem using onbeforeunload in JQuery or Javascript

  1. #1

    Thread Starter
    Fanatic Member vuyiswamb's Avatar
    Join Date
    Jan 2007
    Location
    South Africa
    Posts
    829

    Problem using onbeforeunload in JQuery or Javascript

    Good Day All

    i am opening a Popup and i want to bind the "onbeforeunload" to the popup that if someone clicks on the close button in the window or close button in the page , the event should fire a javascript function that is on the page that opened the popup.

    Code:
     function ProcessPayment(Downloadurl)
            {
             
               
                var url = "http://XXXX.com/cccc_ccccc/2938dc870cd394?tc_id=210&tc_45f=50.0&sig=fc5cbfe44230";
                var popupWindow = window;
    
       popupWindow.onbeforeunload = function () {
                    if (Downloadurl != "") {
                        $.fileDownload(Downloadurl)
                      .done(function () { alert('File download a success!'); })
                      .fail(function () { alert('File download failed!'); });
                    }
                    else {
                        alert("No URL found");
                    }
                }
    
                //open the Popup window
                popupWindow.open(url, 'popUpWindow', 'height=400,width=500,left=10,top=10,resizable=no,scrollbars=yes,toolbar=no,menubar=no,location=no,directories=no,status=yes')
                 //bind the event so that when a user close the windown , we download the file
    when i try this nothing happens the event does not get work and no error in the browsers console

    Thanks

  2. #2
    MS SQL Powerposter szlamany's Avatar
    Join Date
    Mar 2004
    Location
    Connecticut
    Posts
    18,263

    Re: Problem using onbeforeunload in JQuery or Javascript

    If you are using something like Firebug can you set a break point inside the body of the "function () { }" you are creating??

    *** Read the sticky in the DB forum about how to get your question answered quickly!! ***

    Please remember to rate posts! Rate any post you find helpful - even in old threads! Use the link to the left - "Rate this Post".

    Some Informative Links:
    [ SQL Rules to Live By ] [ Reserved SQL keywords ] [ When to use INDEX HINTS! ] [ Passing Multi-item Parameters to STORED PROCEDURES ]
    [ Solution to non-domain Windows Authentication ] [ Crazy things we do to shrink log files ] [ SQL 2005 Features ] [ Loading Pictures from DB ]

    MS MVP 2006, 2007, 2008

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width