/    Sign up×
Community /Pin to ProfileBookmark

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!

to post a comment
JavaScript

5 Comments(s)

Copy linkTweet thisAlerts:
@Angry_Black_ManJun 03.2009 — id personally need to see a stripped down version of your implementation to see this issue in action.
Copy linkTweet thisAlerts:
@sharmi66authorJun 03.2009 — Here is the footer logos:

.

.

.

[SIZE="1"]<div id="copyright"><%= footerMessages.getMessageByKeyAndId(footerResourceKey, "footer.copyright") %></div>

[/SIZE]


<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;
}
}
});
},
Copy linkTweet thisAlerts:
@Angry_Black_ManJun 04.2009 — stick an alert here:

...
//onbeforeunload event handler requires different implementation for IE and Firefox.
window.onbeforeunload = function(evt) {
[COLOR="Red"]alert("the onbeforeunload function was fired. the IF statement will be evaluated next...")[/COLOR]
if (!globalLendingPageUtil.isSubmitting &amp;&amp; !lmbUtil.isPopupSuppressed) {
...


after you place that alert within your code, recreate this problem as described by you:

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.[/QUOTE]

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.
Copy linkTweet thisAlerts:
@sharmi66authorJun 04.2009 — 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>
[/CODE]


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!
Copy linkTweet thisAlerts:
@Angry_Black_ManJun 04.2009 — 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.
×

Success!

Help @sharmi66 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.5,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...