/    Sign up×
Community /Pin to ProfileBookmark

onBeforeUnload fired twice

Hi

We have a jsp page which is inside an IFrame. We want to warn the user when he clicks any other link and leaves the page and ask him if he wants to stay on the current page. Following is the code that has been implemented for this.

window.onbeforeunload = confirmExit;

function confirmExit()

{

return “Do you want to leave this page without saving?”;

}

When the user navigates to another page, the confirm dialog comes up with the message “Do you want to leave this page without saving?”, but if the user select “No” option from the pop-up, the same message pops-up for the second time. If the user selects “No” for the second time, it stays at the current page but the request attributes and parameters already existed in that page are lost. Any one have any idea why this is happening?

If we implement this code without Frame, I mean for plain single page within browser then it works fine.

Thanks

to post a comment
JavaScript

0Be the first to comment 😎

×

Success!

Help @nrupvin 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 6.18,
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: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

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