• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

java script problem

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
author
Posts: 15385
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
Ranch Hand
Posts: 106
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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>
 
A "dutch baby" is not a baby. But this tiny ad is baby sized:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic