View Full Version : auto remove from body tag
chrissy
10-24-2002, 07:24 AM
hi there!
is there any possible way or scripts that will automatically remove the event code at <body> tag by clicking a button?
e.g.
<body topmargin="0" onbeforeunload="script()" leftmargin="0">
when i click on the button the onbeforeunload="script()" will be automatically removed.
:confused:
regards,
chrissy
ConfusedOfLife
10-24-2002, 07:55 AM
<html>
<head>
<title>Untitled</title>
</head>
<body onbeforeunload = "alert('hello')">
<input type="Button" value="Change It!!" onclick="window.document.body.onbeforeunload = '';">
</body>
</html>
chrissy
10-24-2002, 08:19 AM
Hi there,
Thanks for the help i really appreaciate it. I forgot to tell you that im using framed pages.And the button im referring to is the Save button so when i click the Save button the page refresh.Then im gonna click on my left menu links then that alert message still appear.
see the code below :
<body onbeforeunload = "alert('hello')">
<form name="save">
<table border="0" cellspacing="1" width="100%">
<tr class="tablecontent" >
<td width="25%" >00090 - OTHERS</td>
<td width="25%" ><input type="text" name="12" value="14" size="17" class="textbox" ></td>
</tr>
<tr>
<td align="center"><input type="submit" value="Save" onclick="window.document.body.onbeforeunload = '';"> </td>
</tr>
</form>
</table>
</body>
:confused:
regards,
chrissy
chrissy
10-24-2002, 11:54 AM
hi there,
can you help me with this one?
:confused:
:confused:
:confused:
Roy Sinclair
10-24-2002, 03:17 PM
You message is breaking up. Try explaining it again, the last one isn't clear at all.
ConfusedOfLife
10-24-2002, 09:11 PM
I got you! you know what's the problem?! If you do NOT put it in the <form> tag and then you try to run it when it's submitted ( onsubmit ), then everything works just fine, huh?! But if you put it in "onsubmit", then it doesn't work, you know why? Because actually when you press the Submit button, then the whole page's gonna reload, it means that it'll remove the "onbeforeunload" and then it reloads the page that when the compiler reaches the <body> tag, it'll again encounter the "onbeforeunload" and you'll get that annoying hello again! So, what I suppose is that you define a variable, for example submitted in your main frame page and you give 0 to that, then in your page, I mean the page that you have your form and onbeforeunload, you should write :
<head>
</head>
<script>
if ( parent.submitted == 0 )
document.body.onbeforeunload = function() { alert('hello'); }
else
document.body.onbeforeunload = function() {}
</script>
<body>
<form onsubmit="parent.submitted = 1; ">
write the rest of your code in here ...
.
.
.
</body>
So, do you understand what I'm trying to do? You have to have a variable somewhere that when the submit butt is pressed, you change it to something else that then you understand what happend and decide based on that, but you can't make that variable in your current page, coz if for example you set it in here to zero, then you change it onsubmit, when the page is reloading it'll be set to zero again! So, we put it in your parent (framed) page that it doesn't change, now onsubmit we change that variable to 1, meaning that we submitted the form, so when the page is reloading and it reaches our if, it'll go to the else!
chrissy
10-25-2002, 03:03 AM
Hi there,
cant make it run, can you give me other sample,please :confused:
regards,
chrissy
chrismiceli
10-25-2002, 03:56 AM
for frames
<html>
<head>
<script language="javascript">
function hello() {
parent.framename.document.body.onBeforeUnload=";";
}
</head>
<body onBeforeUnload="alert('hi')">
<input type="button" value="test" onClick="hello()">
chrissy
10-25-2002, 05:39 AM
Hi,
what i want is,the alert message will appear if i go to other page without clicking the save button, but once i click the save button the alert message will not appear even i go to other page.
save button click = no alert message when going to other page
save button not click = with alert message when going to other page.
code below:
<SCRIPT LANGUAGE="JavaScript">
var intercept= true;
function messageS(){
if (intercept)
event.returnValue = "Any unsaved information will be lost.";
}
</SCRIPT>
<body onload="intercept = true;" onbeforeunload = "messageS()"> <form name="save">
<table border="0" cellspacing="1" width="100%">
<tr class="tablecontent" >
<td width="25%" >00090 - OTHERS</td>
<td width="25%" ><input type="text" name="12" size="17" class="textbox" ></td></tr><tr><td align="center"><input type="submit" onclick="intercept=false; window.document.body.onbeforeunload = '';" value="Save"> </td></tr></form></table></body>
regards,
chrissy
glenngv
10-25-2002, 06:29 AM
i think this will do the trick:
<input type="submit" onclick="window.onbeforeunload = null">
no need for the boolean flag intercept.
chrissy
10-25-2002, 06:46 AM
hi there, im a little bit desperate with this one.still get the alert message when im clicking links away from this page even i clicked the Save button.
help pls.
glenngv
10-25-2002, 07:23 AM
can you post the modified code?
chrissy
10-25-2002, 07:56 AM
hi heres the code,the problem is when i click save my page refresh.
<SCRIPT LANGUAGE="JavaScript">
var intercept= true;
function messageS()
{
if (intercept)
event.returnValue = "Any unsaved information will be lost.";
}
</SCRIPT>
<body onload="intercept = true;" onbeforeunload = "messageS()">
<form name="save" onsubmit="window.onbeforeunload = null">
<table border="0" cellspacing="1" width="100%">
<tr class="tablecontent" >
<td width="25%" >00090 - OTHERS</td>
<td width="25%" ><input type="text" name="12" size="17" class="textbox" ></td>
</tr>
<tr>
<td align="center"><input type="submit" onclick="window.onbeforeunload = 'null';" value="Save"> </td>
</tr>
</form>
</table>
</body>
regards,
chrissy
glenngv
10-25-2002, 08:28 AM
i didn't enclosed null in quotes.
i modified your code. Copy and paste it:
<html>
<head>
<SCRIPT LANGUAGE="JavaScript">
function messageS()
{
event.returnValue = "Any unsaved information will be lost.";
}
</SCRIPT>
</head>
<body onbeforeunload = "messageS()">
<form name="save">
<table border="0" cellspacing="1" width="100%">
<tr class="tablecontent" >
<td width="25%" >00090 - OTHERS</td>
<td width="25%" ><input type="text" name="12" size="17" class="textbox" ></td>
</tr>
<tr>
<td align="center"><input type="submit" onclick="window.onbeforeunload = null;" value="Save"> </td>
</tr>
</form>
</table>
</body>
</html>
by default, if you don't specify form action, the default action is the current page when it is submitted.
and take note, onbeforeunload only works with IE5+
chrissy
10-25-2002, 08:50 AM
thanks but still have my problem,
Yup when i click save the page refresh to update the database content then remain to the same page, then what i want is after saving, then i will go to other page that alert message will no longer appear coz i already clicked the save button, And it only appears if i go to other module without clicking the save button confirming that all unsaved nformation will be lost.
Is that possible? that alert message will not be appear if i click save button,coz for now even i clicked the save button then i go to other module that alert message still pops,and says any unsave information will be lost.
help me with this one,
thanks,
chrissy
glenngv
10-25-2002, 09:07 AM
put the processing page to db to a different page
<form name="save" action="anotherpagehere">
ConfusedOfLife
10-25-2002, 01:57 PM
Dear glenngv, you said that it's no need for that flag, but whatever we put to cancel the event, when the page reloads ( because of pressing the submit button ), it'll reach the body tag again and will have that onbeforeunload. right?
Ok, I'll right the code for the three pages, the left page, the right page and the main frame page.
Here's the sample code for the left page :
<html>
<head>
<title>Untitled</title>
</head>
<body>
This is the left page<br>
<a href="http://yahoo.com" target="right"> Hello </a>
</body>
</html>
I think you wana put some links in your left page that when the user clicks on them, he be directed to that page, but first gets an alert message if he didn't press the submit in the right page
Here's the code for the right page :
<html>
<head>
<title>Untitled</title>
</head>
<body>
<form onsubmit="parent.flag = 1; document.body.onbeforeunload = function() {}">
<input type="Text">
<input type="Submit">
</form>
<script>
if ( parent.flag == 0 )
document.body.onbeforeunload = function() { alert('hello'); }
</script>
</body>
</html>
And finally the code for your main framed page :
<head>
<title>Untitled</title>
<script>
flag = 0;
</script>
</head>
<frameset cols="100,*">
<frame src="left.html">
<frame src="right.html" name="right">
</frameset>
</html>
I hope that it works...
glenngv
10-28-2002, 12:27 AM
is the action page the same as the current page?
If it is on another page, then the flag is not necessary, that was what I meant. But if the current page is not a pure html page (with server-side scripts in it) and the action page is the current page, then you can remove the onbeforeunload event with server-side coding when it is submitted.
chrissy
10-28-2002, 01:35 AM
Hi ConfusedOfLife
Thank you very much for the help,:thumbsup: Now it's working :o
It gives me what i wanted to happen. It really helps me, thank you very much!
and to Glennv, thank you very much to all your help too.
Thank you guys for helping me out. :p
regards,
chrissy :o
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.