Jump to content

help with clearTimeout


irkevin

Recommended Posts

Hi,

 

what i have is a block of javascript code to refresh contents in an Iframe. So far it works,

 

Now, on the page containing the iframe, i have a form, what i want is, when i move my mouse over the form, the refresh function should stop.

 

here is the html

 

<iframe name="shout" id="shout" src="chat.php" style="overflow:auto;overflow-x: hidden;" frameborder="0" scrolling="yes" marginheight="0" marginwidth="0" height="150" width="100%"></iframe><br /><br />

<form method="post" name="posting" id="posting">
<table width="100%" border="0" cellspacing="0" cellpadding="5">
  <tr>
	<td colspan="6">Your Message:</td>
  </tr>
  <tr>
	<td colspan="6"><input type="text" name="post" id="post" style="width:300px;" />

<input type="submit" value="Submit Shout" name="submit" /></td>
  </tr>
</table>

 

The JS code:

 

<script type="text/javascript">

var milliSecondsToWait = 1000;

function reloadIFrame(){
document.frames['shout'].location.href =
"chat.php?" + (new Date().getTime());
myVar = setTimeout("reloadIFrame()",milliSecondsToWait);
}
var myVar = setTimeout("reloadIFrame()",milliSecondsToWait);

</script>

 

Thats it, how do i clear the timeout when i move my mouse over the <input type="text" .. Help plz

Link to comment
Share on other sites

hum...weird...works in a function though:

 

<input type="text" name="post" id="post" style="width:300px;" onmouseover="stopReload()" />

 

<script type="text/javascript">

var milliSecondsToWait = 1000;

function reloadIFrame(){
document.frames['shout'].location.href =
"chat.php?" + (new Date().getTime());
myVar = setTimeout("reloadIFrame()",milliSecondsToWait);
}
function stopReload ( ) {
  clearTimeout(myVar);
}
var myVar = setTimeout("reloadIFrame()",milliSecondsToWait);

</script>

Link to comment
Share on other sites

did this work for you?

 

Because here when i use this code, when i move my mouseover the textbox, the page still refresh, even when i type in .. i wonder why it wont accept to function stopReload :S

 

i made a test like this:

 

function stopReload ( ) {

alert("I work");

}

 

when i put my mouse over the textbox, i get a message with 'i work'.. Which mean the function works but it looks like the clearTimeout isn't working.. Any ideas?

Link to comment
Share on other sites

this worked for me:

<iframe name="shout" id="shout" src="chat.php" style="overflow:auto;overflow-x: hidden;" frameborder="0" scrolling="yes" marginheight="0" marginwidth="0" height="150" width="100%"></iframe><br /><br />

<form method="post" name="posting" id="posting">
<table width="100%" border="0" cellspacing="0" cellpadding="5">
     <tr>
      <td colspan="6">Your Message:</td>
     </tr>
     <tr>
      <td colspan="6"><input type="text" name="post" id="post" style="width:300px;" onmouseover="stopReload()" />
      
<input type="submit" value="Submit Shout" name="submit" /></td>
     </tr>
</table>
<script type="text/javascript">

var milliSecondsToWait = 1000;

function reloadIFrame(){
document.getElementById('shout').src =
"chat.php?" + (new Date().getTime());
myVar = setTimeout("reloadIFrame()",milliSecondsToWait);
}
function stopReload ( ) {
  clearTimeout(myVar);
}
var myVar = setTimeout("reloadIFrame()",milliSecondsToWait);

</script>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.