Forum Moderators: open

Message Too Old, No Replies

Wanted please a script to close a link at certain times.

javascript help

         

nigelbriganti

9:24 am on Sep 28, 2006 (gmt 0)

10+ Year Member



hello everyone

i am in need of a piece of code that closes one of my links at certain times of the day.. its a link to my chat room that i only want open between midday and say 3'oclock..

any help would be much appreciated..

penders

10:27 am on Sep 28, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Hi nigelbriganti, welcome to WebmasterWorld. You could disable a link (an anchor tag?) to your chat room, but what if someone already knew what the link to the chatroom was? They could simply type in the URL and bypass your link. Is it not better to have code on your chatroom page that disables the chatroom itself between midday and 3pm?

nigelbriganti

2:08 pm on Sep 28, 2006 (gmt 0)

10+ Year Member



hi and thaks v much for your time.. what type of code would i use?

penders

2:37 pm on Sep 28, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



For it to be secure, you would need access to some server-side scripting (if you have a 'chatroom', I guess you already have?) ... PHP perhaps?

Also, I assume this is between midday and 3pm wherever *you* are (same timezone) - so is possibly the same time as the server?

nigelbriganti

3:36 pm on Sep 28, 2006 (gmt 0)

10+ Year Member



yes the chat we are using is in fact php.. and yes the times would be server time and your right about the times too! are you sure your noe inside my computer! again thanks for your help and any more would be great!

nigel

penders

6:44 pm on Sep 28, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Diving into the PHP... if you place the following at the top of your document:

<?php 
$hrs = date('G');// Current Hrs - 24hr clock
if (($hrs < 12) ¦¦ ($hrs >= 15)) {
print <<<END
<html>
<head><title>Chatroom</title></head>
<body>
<h1>Chatroom - Offline</h1>
<p>The chatroom can only be accessed between midday and 3pm.</p>
<p>Please come back later.</p>
</body>
</html>
END;
exit;
}
?>

That should work. If it is 'out of hours' then the rest of your page will not be rendered (exit;) and you just get a simple page returned. You might be able to do header() redirect to another page instead if you wish - not sure which is best in terms of search engines, if that is of concern...?

(I'll get out of your computer now... bit dusty in there anyway! ;)

nigelbriganti

4:22 pm on Oct 2, 2006 (gmt 0)

10+ Year Member



thank you!

[edited by: DrDoc at 4:37 pm (utc) on Oct. 2, 2006]
[edit reason] spliced from orphaned thread [/edit]

Angelis

4:29 pm on Oct 2, 2006 (gmt 0)

10+ Year Member



np

nigelbriganti

8:24 am on Oct 3, 2006 (gmt 0)

10+ Year Member



Hi again,

I tryed that in my code and i cant seem to get it working..

here it is.. Could you please have a look and see where you think i should put that code? please..

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html><!-- InstanceBegin template="/Templates/mainnigel.dwt" codeOutsideHTMLIsLocked="false" -->
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<!-- InstanceBeginEditable name="doctitle" -->
<title>Craic at the Village Chatroom</title>
<!-- InstanceEndEditable --><link href="css/mainnigel.css" rel="stylesheet" type="text/css">
<!-- InstanceBeginEditable name="head" --><!-- InstanceEndEditable -->
<script src="Scripts/AC_RunActiveContent.js" type="text/javascript"></script>
<style type="text/css">
<!--
a:link {
text-decoration: none;
}
a:visited {
text-decoration: none;
}
a:hover {
text-decoration: none;
}
a:active {
text-decoration: none;
}
.style1 {color: #139433}
-->
</style></head>

<body>
<table width="737" border="0" align="center" cellpadding="0" cellspacing="0" bgcolor="#139433">

<tr>
<td align="center" ><span class="style1"><!-- InstanceBeginEditable name="EditRegion4flashbanner" -->
<script type="text/javascript">
AC_FL_RunContent( 'codebase','http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0','width','700','height','160','title','banner','src','images/banner_restofsite','quality','high','pluginspage','http://www.macromedia.com/go/getflashplayer','movie','images/banner_restofsite' ); //end AC code
</script><noscript><object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0" width="700" height="160" title="banner">
<param name="movie" value="images/banner_restofsite.swf">
<param name="quality" value="high">
<embed src="images/banner_restofsite.swf" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="700" height="160"></embed>
</object></noscript>
<!-- InstanceEndEditable --></span></td>
</tr>
<tr>
<td bgcolor="#000000" align="center"> <div class="nav">
<ul>
<li><a href=""></a></li>
<li><a href="index.htm">Home </a></li>
<li><a href="readingepisodes.htm">Get Started </a></li>
<li><a href="back_episodes.htm">Back Episodes </a></li>
<li><a href="characterbiogs.htm">Character Biographies </a></li>
<li><a href="chattest.html"> Chat Room </a></li>
<li><a href="aboutus.htm"> About Us </a></li>
</ul></div></td>
</tr>
</table>

<!-- InstanceBeginEditable name="bodyarea" -->
<table width="737" border="0" align="center" cellpadding="0" cellspacing="0" bgcolor="#139433">
<tr>
<td align="center" valign="middle"><p><iframe src="http://www.craicatthevillage.com/mychat/chat/" name="chat_iframe" width="728" marginwidth="0" height="450" marginheight="0" align="middle" scrolling="auto" frameborder="0"><a href="http://www.craicatthevillage.com/mychat/chat/">chat</a></iframe>
</p></td>
</tr>
</table> </table>
<table width="737" height="94" border="0" align="center" cellpadding="0" cellspacing="0" background="images/background2.jpg">
<tr></tr>
<tr height="5"></tr>
<tr>

</tr>
</table>
<table width="728" border="0" align="center" cellpadding="0" cellspacing="0">
</table>
<!-- InstanceEndEditable -->

</body>
<!-- InstanceEnd --></html>

penders

10:21 am on Oct 3, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



I tryed that in my code and i cant seem to get it working..

here it is.. Could you please have a look and see where you think i should put that code? please..

That code should go at the very start of your document, before the DOCTYPE...

<?php 
// PHP CODE HERE....
?>
<!DOCTYPE HTML PUBLIC...... etc.

Your page will also need to end in ".php" (for the PHP to get parsed by the server), which I had assumed it was since you have a PHP chatroom?

You have to be a little careful that the 'print <<<END' block is exactly as shown, with (the closing) 'END;' on its own with no space before or after.

Do you get any errors reported?