www.webdeveloper.com
Results 1 to 6 of 6

Thread: onbeforeunload issues

  1. #1
    Join Date
    Jun 2009
    Posts
    3

    onbeforeunload issues

    Hi
    We use the onbeforeunload function on a page to try to get the users to stay on the page. if the form is being submitted, then we dont throw the "confirm" box.
    Here is the problem: On the same page, we have a footer with various logos (verisign etc) and if the user clicked on that logo (which pops up a separate window) and then came back to the page they were actually in and try to navigate away, the onbeforeunload never fires.

    Is there any solution to this?

    Thanks for your help!

  2. #2
    Join Date
    May 2005
    Location
    Dirty Jersey
    Posts
    1,401
    id personally need to see a stripped down version of your implementation to see this issue in action.

    1. If you reply to my post, and your reply would then appear directly beneath my post, DON'T QUOTE MY ENTIRE POST!!! IT'S REDUNTANT!!! IT'S ASININE!!!! IT'S REDUNDANTLY ASININE!!!!! DON'T DO IT!!!!
    2. jQuery extends the functionality of JavaScript. If you don't know JavaScript, give up on that jQuery script and learn JavaScript. You'll save yourself a lot of frustration, I promise.
    3. Use the [code][/code] tags. Otherwise, you may be left wondering why no one responded to your eyesore of a thread.


  3. #3
    Join Date
    Jun 2009
    Posts
    3

    code snippet

    Here is the footer logos:
    .
    .
    .
    <div id="copyright"><%= footerMessages.getMessageByKeyAndId(footerResourceKey, "footer.copyright") %></div>

    <div id="logos">
    <a id="footerHud" href="http://www.hud.gov/" target="_blank"><img src="<%= footerAkamaiBaseHref %>/images/cobrands/hud_logo.gif" alt="U.S. Department of Housing and Urban Development" align="middle" border="0" height="56" width="64"></a>
    .
    .
    .

    Here is the event handler itself
    globalLendingPageUtil.registerEventListener(globalLendingPageUtil.POST_DATA_BIND_PROCESS, function(data) {
    //onbeforeunload event handler requires different implementation for IE and Firefox.
    window.onbeforeunload = function(evt) {

    if (!globalLendingPageUtil.isSubmitting && !lmbUtil.isPopupSuppressed) {
    var message = globalLendingPageUtil.getProcessedContentElementEntity(data, contentElements.CE_4014);
    if (typeof evt == 'undefined') {
    evt = window.event;
    }
    if (evt) {
    var f = window.document.application;
    evt.returnValue = message;

    }
    return message;
    }
    }
    });
    },

  4. #4
    Join Date
    May 2005
    Location
    Dirty Jersey
    Posts
    1,401
    stick an alert here:

    Code:
    ...
    //onbeforeunload event handler requires different implementation for IE and Firefox.
    window.onbeforeunload = function(evt) {
    alert("the onbeforeunload function was fired. the IF statement will be evaluated next...")
    if (!globalLendingPageUtil.isSubmitting && !lmbUtil.isPopupSuppressed) {
    ...
    after you place that alert within your code, recreate this problem as described by you:

    Quote Originally Posted by sharmi66 View Post
    On the same page, we have a footer with various logos (verisign etc) and if the user clicked on that logo (which pops up a separate window) and then came back to the page they were actually in and try to navigate away, the onbeforeunload never fires.
    if you see the alert, the IF statement below the inserted alert is where your problem lies, and you will need to debug that IF statement.

    if you DON'T see the alert, please create a small script that does NOT contain any ASP script that duplicates/emulates your problem. post the script to the thread so that anyone can run the script and have it already duplicate your problem.

    1. If you reply to my post, and your reply would then appear directly beneath my post, DON'T QUOTE MY ENTIRE POST!!! IT'S REDUNTANT!!! IT'S ASININE!!!! IT'S REDUNDANTLY ASININE!!!!! DON'T DO IT!!!!
    2. jQuery extends the functionality of JavaScript. If you don't know JavaScript, give up on that jQuery script and learn JavaScript. You'll save yourself a lot of frustration, I promise.
    3. Use the [code][/code] tags. Otherwise, you may be left wondering why no one responded to your eyesore of a thread.


  5. #5
    Join Date
    Jun 2009
    Posts
    3

    Thanks much!

    Aaron
    First of all, thank you so much for taking the time to help me out. I tried creating a separate script as you suggested and I am unable to reproduce the same problem:

    Code:
    <html>
    <head>
    	<script type="text/javascript">
    		window.onbeforeunload = function(evt) {
    			var message = "Stay Here Please!!!";
    			if (typeof evt == 'undefined') {
    				evt = window.event;
    			}
    			if (evt) {
    				evt.returnValue = message;
    
    			}
    			return message;                
    		}
    		
    	</script>
    </head>
    <body>
    <a id="footerHud" href="http://www.hud.gov/" target="_blank">U.S. Department of Housing and Urban Development</a>
    </body>
    </html>
    The above html works fine.

    I tried the IF stmt for debugging and it never fired after the popup was launched from the footer
    Any other ideas?
    Thanks again for your time!

  6. #6
    Join Date
    May 2005
    Location
    Dirty Jersey
    Posts
    1,401
    the only idea i have left are to check for errors in your "console". beyond that, the only way to troubleshoot this issue is a direct link to your site. i would be at a serious disadvantage trying to troubleshoot code that has asp in it.

    1. If you reply to my post, and your reply would then appear directly beneath my post, DON'T QUOTE MY ENTIRE POST!!! IT'S REDUNTANT!!! IT'S ASININE!!!! IT'S REDUNDANTLY ASININE!!!!! DON'T DO IT!!!!
    2. jQuery extends the functionality of JavaScript. If you don't know JavaScript, give up on that jQuery script and learn JavaScript. You'll save yourself a lot of frustration, I promise.
    3. Use the [code][/code] tags. Otherwise, you may be left wondering why no one responded to your eyesore of a thread.


Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles