• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

java script problem

 
kanumuri koti
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi everyone,

I have a data grid and 2 buttons on a page, when a user cancels the window, i want to displat a popup asking the whethere they are sure they want to cancel.

i currently have

<SCRIPT>
function SaveChanges()
{
event.returnValue = "You will loose all unsaved changes, please update details before closing the window.";
}
</SCRIPT>



i call this function on the body like

<body bgColor="#ffffff" MS_POSITIONING="GridLayout" onbeforeunload="SaveChanges()">



Problem is, this message comes up even when clicking the buttons on the page, which is wrong, i want it to happen only when the user closes/cancels the window. Please help

[ December 13, 2006: Message edited by: kanumuri koti ]
[ December 13, 2006: Message edited by: Bear Bibeault ]
 
Eric Pascarello
author
Rancher
Posts: 15385
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You need to add a flag to all of the events that cause a post back. (aka set a JavaScript variable onclick) In the SaveChanges you have to check to see if that flag/bit was flipped or not. Than you know if it should be shown.

You will never get the same feel as a client application.

Eric
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64720
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As a favor I have removed the "very urgent" from the title. Please read this to find out why that's a really bad idea.

You could also use better subjects. Also read this.
[ December 13, 2006: Message edited by: Bear Bibeault ]
 
Neerav Narielwala
Ranch Hand
Posts: 106
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can also use the "closed" property on the window.opener object to determine whether the window that opened the window in question is still open (are you still with me?). For example:


<script type="text/javascript">
if (window.opener.closed)
alert("You killed my boss!")
else
alert("My boss is still alive!")
</script>
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic