...

View Full Version : OnUnload Refresh



BigRusky
08-05-2008, 07:48 PM
Hello,

I have an onunload event, but i dont want it to start during refresh. Is there a way to stop that.

-Steven

ninnypants
08-05-2008, 08:19 PM
You might be able to run it when one of your navigation items is clicked, but you will be able to get better responses if you post your code.

BigRusky
08-05-2008, 10:53 PM
all i want is an onunload event to occur when user leaves page, but i have a form and when user clicks submit, the onunload event also occurs which i dont want.

sorry for the inconvenience.

rangana
08-06-2008, 03:45 AM
Have you tried to create a global variable, and set it either 1/0. If the user submits, then set that variable to 0 and in your onunload function, have something along this lines:


var flag=1;
onunload=function(){
if(flag) // Message when the user leaves
}


Hope that makes sense. If nothing works, up the code so we could have something to play with.

BigRusky
08-06-2008, 04:27 AM
how would u submit the flag var

my code:



<?
include "auto.php";
$page = new ArmyPage("onunload=\"steven();\"");

if (isset($_POST['submit_chat']) && $_POST['submit_chat'] == "Submit") {
if ($_POST['msg'] != "") {
$query = mysql_query("INSERT INTO chat (name, msg, aid) VALUES ('".$_SESSION['name']."', '".$_POST['msg']."', '".$_GET['a']."')") or die(mysql_error());
} else {
//Do nothing
}}else{
}

//rank check:
if ($_SESSION['arank'] == "Leader") {
$rank = "leader";
} elseif ($_SESSION['arank'] == 1) {
$rank = 1;
} else {
$rank = "all";
}

$page->PrintHeader();
?>
<script language="javascript" type="text/javascript">
new Ajax.PeriodicalUpdater('content', 'chatdiv.php?a=<? echo $_GET['a'] ?>', {
frequency: 2, decay: 1
});
</script>
<div id="chat">
<div class="header">
Welcome to chat!
</div>
<div id="content">
<?
$q = mysql_query("SELECT * FROM chat WHERE aid = '".$_GET['a']."' ORDER BY `id` DESC") or die(mysql_error());
while ($r = mysql_fetch_array($q)) {
?>
<span class="name"><? echo $r['name'] ?>:</span>
<span class="msg">
<? echo $r['msg'] ?>
</span><br />
<?
}
?>
</div>
<a name="bottom"></a>
</div>
<div id="submit">
<form method="post" action="achat.php?a=<? echo $_GET['a'] ?>">
<input type="text" size="35" name="msg" />
<input name="submit_chat" type="submit" value="Submit" />
</form>
</div>
<?
$page->PrintFooter();
?>



Note: the unonload event is attached to the body tag through classes

rangana
08-06-2008, 04:50 AM
And the steven function?

BigRusky
08-06-2008, 05:30 AM
o sry that was a test

that is the onunload function its just not defined.

rangana
08-06-2008, 06:10 AM
Here's a basic example of what I believe would work:


<script type="text/javascript">
var flag=1;
window.onload=function(){
document.forms[0].onsubmit=function(){flag=0;}}
window.onunload=function(){
if(flag) alert('I know, you are leaving');}
</script>
<a href="http://www.google.com">test [Google]</a><br>
<a href="http://www.codingforums.com">test [CodingForums]</a>
<form action="http://www.codingforums.com">
<input type="submit" value="Submit">
</form>

It does'nt alert any message when you submit the form. Only when submitting the form.
Hopefully, this should work at your end.

BigRusky
08-06-2008, 06:42 AM
thanks ur code works but my class system is all messed up and is ruining it so i have to look at that.

BigRusky
08-23-2008, 12:53 AM
Hello again,

I have got the onunload event to finally work! But, ....

Is there some way to stop the event from happening when the page is refreshed? Like, is there a way to find out what page the person came from, when going to this one?

-Steven



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum