Our web application open a popup browser window contains a cutomized LiveCycle workspace from where the user submit a data form. I want to implement a feature that when the user close the browser window, a message box will pop up for user's confirmaiton (OK to close the window, Cancel to remain in the workspace window). Here is my code:
In javascript:
<script LANGUAGE="JavaScript">
window.onbeforeunload = confirmExit;
var needToConfirm = true;
var confirmMsg = "Are you sure you want to exit this page?"
function confirmExit() {
if (needToConfirm) {
alert("Event triggered!");
event.returnValue = confirmMsg;
//return confirmMsg;
}
}
function setNeedConfirm() {
needToConfirm = true;
}
function releaseNeedConfirm() {
needToConfirm = false;
}
</script>
In *.mxml:
flash.external.ExternalInterface.call("releaseNeedConfirm"); or flash.external.ExternalInterface.call("setNeedConfirm");
This approach works perfectly with IE, but for some reason it does not work with FireFox. I confirmed that the line alert("Event triggered!") is reached in FF, but no confirmation box is popped up.
Anyone can help me here?
Thanks
John
Views
Replies
Total Likes
Just change the line of code:
event.returnValue = confirmMsg;
as the following;
event.preventDefault = confirmMsg;
Hope this will work!
Nith
Views
Replies
Total Likes
Thank you Nith, but I tried it with no luck, and it stopped working in IE. Anything else I can try?
Views
Replies
Total Likes
The code I mentioned is applicable only to FireFox.
To make your logic work on both browsers, you need to find out the browser type and should handle the event accordingly.
-Nith
Views
Replies
Total Likes
You can detect the browser type by:
var browser=navigator.appName;
var b_version=navigator.appVersion;
var version=parseFloat(b_version);
alert("Browser name: "+ browser);
alert("Version: "+ version);
-Nith
Views
Replies
Total Likes
I did check in both IE and FF but the browser juct closed silently. Did I miss anything in the code?
Views
Replies
Total Likes
I will try to make an example and then let you know.
Nith
Views
Replies
Total Likes
If I put the javascript into a standard HTML, it works fine in both IE and FF. But once I put it in a HTML of a Flex application it stops working with FF.
Views
Replies
Total Likes