/    Sign up×
Community /Pin to ProfileBookmark

Is there any way to stop window closing with onunload?

Hi,
I am looking to do a “Are you sure you want to leave the page” message as part of a web-based applciation using onUnload and confirm().
I cannot figure out how to make it such that when the user clicks ‘Cancel’ they does not leave the page.

Any ideas on how to do this?

to post a comment
JavaScript

7 Comments(s)

Copy linkTweet thisAlerts:
@JonaSep 15.2003 — [font=monospace]

<body onunload="if(confirm('Are you sure you want to exit?')){return true;}else{return false;}">

[/font]

[b][J]ona[/b]
Copy linkTweet thisAlerts:
@AdamGundrySep 15.2003 — Jona, your code does not work on IE 6 or Mozilla 1.4. AFAIK, there is no reliable way you can do this, as it is a browser security issue. You may be able to put a window.open() call in the onunload handler to reopen the window.

Adam
Copy linkTweet thisAlerts:
@JonaSep 15.2003 — [i]Originally posted by AdamGundry [/i]

[B]Jona, your code does not work on IE 6 or Mozilla 1.4. AFAIK, there is no reliable way you can do this, as it is a browser security issue. You may be able to put a window.open() call in the onunload handler to reopen the window.[/B][/QUOTE]


[font=arial][color=maroon]I don't know why I even "answered" the question... I don't particularly enjoy dealing with this sort of thing... I'll remember not to respond to these kinds of posts anymore. :p[/color][/font]

[b][J]ona[/b]
Copy linkTweet thisAlerts:
@AdamGundrySep 15.2003 — If we can get [url=http://www.webdevfaqs.com/]WebDevFaqs[/url] up and running, we should just be able to answer simple questions by posting links. ?

Adam
Copy linkTweet thisAlerts:
@JonaSep 15.2003 — [i]Originally posted by AdamGundry [/i]

[B]If we can get [url=http://www.webdevfaqs.com/]WebDevFaqs[/url] up and running, we should just be able to answer simple questions by posting links. ?[/B][/QUOTE]


[font=arial][color=magenta][b][size=4]w00t![/size][/b][/color][color=maroon] lol... [/color][/font]

[b][J]ona[/b]
Copy linkTweet thisAlerts:
@blacibFeb 01.2004 — [i]Originally posted by AdamGundry [/i]

[B]You may be able to put a window.open() call in the onunload handler to reopen the window.



Adam [/B]
[/QUOTE]


The opening of a new window does it work also with GoogleBar?
Copy linkTweet thisAlerts:
@JonaFeb 01.2004 — [i]Originally posted by blacib [/i]

[B]The opening of a new window does it work also with GoogleBar? [/B][/QUOTE]


[font=arial]Not if the GoogleBar is a good popup blocker...[/font]

[b][J]ona[/b]
×

Success!

Help @jovialjonny 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,
)...