Is it possible to stop a page from loading with onUnload?

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
myleow
Forum Contributor
Posts: 194
Joined: Mon Jun 21, 2004 7:05 pm
Location: California

Is it possible to stop a page from loading with onUnload?

Post by myleow »

Hi guys,

I am messing around with onUnload and would like to know if there is a way to stop users from going to other pages if there were changes in the current page.

Like i change some field values and then click on something else (another page link) besides the Update Cart button, i would like to make it so that they get an Alert saying You made changes please click on Update Cart first and stop the redirection.

You can check it out at http://www.impressiondesign.com/deanes/ add something to the cart and then go to view cart, if you change something on the cart (quantity) and click on Products or any other links besides Update Cart button or Checkout button. I want it to stop the loading of the page and stay in that page.

Thank you for your help in advance.

Regards
Mian
User avatar
Burrito
Spockulator
Posts: 4715
Joined: Wed Feb 04, 2004 8:15 pm
Location: Eden, Utah

Post by Burrito »

onUnload is all but phased out... you should just check on the server side then send them back if the stuff is not the way you want it.
myleow
Forum Contributor
Posts: 194
Joined: Mon Jun 21, 2004 7:05 pm
Location: California

Post by myleow »

Yeah i ended up giving up on the idea of using it. Thanks for the information.
foobar
Forum Regular
Posts: 613
Joined: Wed Sep 28, 2005 10:08 am

Post by foobar »

Burrito wrote:onUnload is all but phased out...
Uh, no. MSN WebMessenger uses it, my router's html interface uses it, and most other web chat applications that log the user off once they've quit the page (including one I wrote).
User avatar
Burrito
Spockulator
Posts: 4715
Joined: Wed Feb 04, 2004 8:15 pm
Location: Eden, Utah

Post by Burrito »

in what capacity do they use it? In other words, how is it used effectively? Does it pop-up a new window?
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post by Chris Corbyn »

Burrito wrote:in what capacity do they use it? In other words, how is it used effectively? Does it pop-up a new window?
Popup blockers will stop that. You may still be able to throw an alert box but I guess that *might* be blocked too.

The only things I can think of onunload working for are data transmissions using ajax or such, back to the server.
User avatar
Burrito
Spockulator
Posts: 4715
Joined: Wed Feb 04, 2004 8:15 pm
Location: Eden, Utah

Post by Burrito »

d11wtq wrote: Popup blockers will stop that. You may still be able to throw an alert box but I guess that *might* be blocked too.
precisely my point....
foobar
Forum Regular
Posts: 613
Joined: Wed Sep 28, 2005 10:08 am

Post by foobar »

Burrito wrote:in what capacity do they use it? In other words, how is it used effectively? Does it pop-up a new window?
Forget it, I was thinking of onBeforeUnload. Stupid me. :oops:
Post Reply