Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

MacinTosh/JavaScript question

Status
Not open for further replies.

tboerner

Programmer
Oct 19, 2001
23
US
The following code brings up a message box on my PC (MS IE 5.0), but doesn't function for the Mac. Any ideas on what I can do? The code does fire on the Mac, but return statement doesn't do anything.

<SCRIPT LANGUAGE=&quot;javascript&quot;>
var submitted;
submitted = false;
function window.onbeforeunload() {
if (submitted == false) {
return &quot;If you leave, changes will not be saved.&quot;;
}
}
</SCRIPT><


 
What you need is :

<SCRIPT LANGUAGE=&quot;javascript&quot;>
var submitted;
submitted = false;
function window.onbeforeunload() {
if (submitted == false) {
alert('If you leave, changes will not be saved.');
}
}
</SCRIPT> Regards

Big Dave

davidbyng@hotmail.com
 
Dave,

I don't think the alert will work. The way it works (on the PC), a choice of continuing (or not) is given. Alerts don't give choices.

Tim
 
Got it working with this.

<HTML>
<HEAD>
<SCRIPT>
function closeIt()
{
event.returnValue = &quot;Any string value here forces a dialog box to appear before closing the window.&quot;;
}
</SCRIPT>
</HEAD>
<BODY onbeforeunload=&quot;closeIt()&quot;>
 
Try this :

<SCRIPT LANGUAGE=&quot;javascript&quot;>
var submitted;
submitted = false;
function foo() {
if (submitted == false) {
if (confirm(&quot;If you leave, changes will not be saved.&quot;))
return true;
else
return false;
}
}
</SCRIPT>
<body onbeforeunload=&quot;return foo()&quot;> Regards

Big Dave

davidbyng@hotmail.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top