Hi Guys,
I have attached the beforeunload event and its handler to the window as :
// this is FireFox only
window.addEvent Listener("befor eunload",before unloadHandler,f alse);
function beforeunloadHan dler(event){
event.returnVal ue="my message !";
}
now the string "my message !" will be display on a confirm dialog box ,
my question could I hide that dialog box, or at least prevent it from being shown .
of course my goal is to prevent the default behavior of the beforeunload event .
I have tried event.preventDe fault(). I get the dialog box again .
any comments ?
thanks .
5 10405 acoder 16,027
Recognized Expert Moderator MVP
I doubt this can be done or at least I have not seen a way to prevent the dialog box. It's there for usability, otherwise you could force someone to stay on the page unless they disable JavaScript.
I doubt this can be done or at least I have not seen a way to prevent the dialog box. It's there for usability, otherwise you could force someone to stay on the page unless they disable JavaScript.
what about method overriding such as :
window.confirm = function (){ }
I have tried that, but still the dailog box appears .
but are there any other ways to detect that this window will be unloaded . of course without any alerts or confirm boxs .
thanks .
acoder 16,027
Recognized Expert Moderator MVP
The onbeforeunload dialog box is not the same as the JavaScript confirm() method.
The alternative to onbeforeunload is, of course, onunload. The problem is that once onunload fires, you can't ask the user to stay on the page.
Why do you want to prevent the default behaviour?
The onbeforeunload dialog box is not the same as the JavaScript confirm() method.
The alternative to onbeforeunload is, of course, onunload. The problem is that once onunload fires, you can't ask the user to stay on the page.
Why do you want to prevent the default behaviour?
well, simply I want to detect which url will unload my current document, since beforeunload event could be stopped by the user (dialog box), then this would be annoying for users.
now, inside the unload event handler, could I know which url will replace my current document . of course I cann't stop the unload event, but at least I want to know the url .
thanks.
acoder 16,027
Recognized Expert Moderator MVP
well, simply I want to detect which url will unload my current document, since beforeunload event could be stopped by the user (dialog box), then this would be annoying for users.
now, inside the unload event handler, could I know which url will replace my current document . of course I cann't stop the unload event, but at least I want to know the url .
thanks.
I don't think you can. If you try to get information from the History object, you'll probably get a permission denied warning.
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: jennyw |
last post by:
Hi,
I'd like to use onbeforeunload to submit a form before leaving a page.
This works in Firefox and IE. Safari, however, blithely ignores this.
Does anyone know of a workaround for Safari? Or another way to do the
same thing in Safari? (that is, intercept a request to leave the page).
I tried Safari 2.02 on Tiger.
Thanks!
|
by: Tony |
last post by:
OK - I know the mantra, so let's be clear: I'm working on a web
application that we want to be able to simply warn the user that they
might lose data (or the current application state - it's .NET) if they
navigate away from the page using the Back button. I was thinking of
using onbeforeunload (which seems to work with IE, FF, and Netscape, but
not Opera & Safari - that is acceptable).
The problem is that if I define onbeforeunload, even...
|
by: gene kelley |
last post by:
I have a dialog form, frmDetails, that is opened from the main form:
frmDetails.ShowDialog()
The only way I have provided to close this dialog is via the "X" button.
If frmDetails is just closed as normal, there is no visual problem (no repainting) with the main
form.
Now, I add this code to the the FormClosing event in the dialog, frmDetails:
|
by: Jason |
last post by:
Hello everyone,
I have a chatroom. If someone leaves, I need to tell the server that
person has left. Currently i catch window.onbeforeunload to check if
the person tries to leave. I noticed that when I don't have a dialog
popup asking if the person really wants to leave, my Ajax-request code
doesn't always get sent to the server. Basically, the popup ensures my
beforeunload code gets executed. Why is this?
Also, when I try to stop the...
|
by: allan.young |
last post by:
Hi,
When in gmail I'm composing a new email message and I bit the browser
back button, I get a dialog that says "Your message has not been sent.
Discard your message?"
But if instead of clicking Back, I hit the Browser Close button, I get
the above message, PLUS if I click "cancel" on that dialog, I get the
following message 'Are you sure you want to navigate away from this
page? Press "Cancel" to remain on this page. Press OK to...
| |
by: deciacco |
last post by:
I'm trying to write a label printing SDI app with a small preview on the main form itself. Every time I run the InvalidatePreview event on the preview
control to redraw the preview I get the "Generating Previews" dialog box while the preview is being generated. I want to suppress this. I've been able
to find this from another forum:
"The 'Generating Previews' dialog is shown while calculating the layout for pages in OnPaint(). One of our...
|
by: haymansfield |
last post by:
Hi,
Im trying to capture the value the user inputs into the dialog box
brought up when the onBeforeUnload event is given an
event.ReturnValue.
If the user selects ok i dont need to do anything but if he selects
cancel (stay on the same page) I want to change the value of a
variable.
|
by: Frinavale |
last post by:
Introduction
I've seen many questions asked about how to disable the browser's back button and in the past I've replied with "it's simply not possible". It's not a good idea to disable the back button anyways, if the user ventures away from your page then they wouldn't have this button at their disposal.
The main reason people ask how to control or disable the back button is because they have a need to control sensitive (and/or) dynamic web...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
| |
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |