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!

stop a link from working between certain times 1

Status
Not open for further replies.

brightstar

Technical User
Sep 20, 2002
233
Hey there.
all i want to do is make sure that either a link doesnt appear, it goes to a certai place or it just doesnt work or whatever.
but if its between 12 and 2 in the afternon, i want it to work or appear or go to the intended site.
also, if possible how can you not show the address of the page whenit gets there?

free, anonymous advice provided by the whole world
 
You could use javascript to determine the time and if it meets your criteria output a document.write(<a href> </a>)

About the only way I know of to get a link not to show up is keep your page in a frameset instead of jumping to the other page. Or by making the address bar disappear like in a pop-up window.



Regards,
Tread42
 
What language do you use?
It would need to be done server side (for security) and I think it would be very simple for someone with a little programming knowledge.

Check & compare time, if time is between 12 & 2 display link A or otherwise display link B.

With SSI it could be done like:

<!--#config timefmt=&quot;%H&quot; -->
<!--#set var=&quot;time&quot; value=&quot;$DATE_LOCAL&quot; -->
<!--#set var=&quot;limit1&quot; value=&quot;12&quot; -->
<!--#set var=&quot;limit2&quot; value=&quot;14&quot; -->
<!--#if expr=&quot;($time>$limit1)
&& ($time<$limit2)&quot; -->

Display this link between 12:00 & 14:00

<!--#else -->

Display this other link

<!--#endif -->


Note I haven't check this code, just wrote it on the spot (more or less). It might be easier in PHP?

Before u test it, does your server support SSI? Do you know how ot use SSI?





<!--#sig value=''É'' url='' -->
 
Cian,

I see you have written quite a bit on SSI. Can you please look at my post thread216-693637 ? I'm attempting to use javascript/SSI to randomly replace a table that contains an ad.

I've tried using your FAQ article but the ad I'm trying to rotate repeats itself over an over several times.

Sorry to interrupt this post, but I didn't see any way to contact you via email or private post.



Regards,
Tread42
 
ok, now i want to do it in javascript.
but my javascript syntax is crap.
i know its something along the lines of:

var time = systemtime
if systemtime == > 12 and < 14 then
{
document.write (all the stuff i wanna display)
else
document.write )come back between 12 and 2)
end if
}

the syntax of that is probabaly a crap mix of javascript and vba.. help!

free, anonymous advice provided by the whole world
 
This ought to work for you...

Code:
<script type=&quot;text/javascript&quot; language=&quot;Javascript&quot; />
var now = new Date();
if (now.getHours() >= 12 && now.getHours() <= 14)
{
  // we are inside of these hours, write out the href
  document.write('<a href=&quot;[URL unfurl="true"]http://www.tek-tips.com&quot;>Visit[/URL] Tek-Tips</a>');
} else {
  // outside of these hours you can do something else
}
</script>

All the best,
Jeff
 
So why the hell isnt this working? it doesnt seem to be able to work out the time now that i have put all the text in.

<script type=&quot;text/javascript&quot;>
var now = new Date()
var time = now.getHours()

txt1=&quot;<p class='mainheader'>AS IPT Games</p>&quot;
txt2=&quot;<p class='subheader'>Here are some games to play on your lunch break only!</p>&quot;
txt3=&quot;<font class='maintext'>&quot;
txt4=&quot;<p>You will need a current IGS account to make use of this facility:</p>&quot;
txt5=&quot;<p><a href =' target='games'>Solitaire</a></p>&quot;
txt6=&quot;<p><a href =' target='games'>Frogger</a></p>&quot;
txt7=&quot;<p><a href =' target='games'>Balls</a></p>&quot;
alltxt=txt1 + txt2 + txt3 + txt4 + txt5 + txt6 + txt7

if (time >= 12 && time <= 14)
{
document.write(alltxt)
}
else
{
document.write(&quot;<p font class='maintext'>Please come back between the hours of 12pm and 2pm</p>&quot;)
}
</script>
<iframe name=&quot;games&quot; width=100% height=0% src=&quot;&quot;>
</iframe>


free, anonymous advice provided by the whole world
 
All I have done is reformat your code to remove your use of single quote ' when you output your HTML. Javascript will use &quot; or ' whereas HTML tags will use &quot; only.

I also took the liberty of tidying up how you build your text variables before outputing:

Code:
<script type=&quot;text/javascript&quot;>
var now = new Date()
var time = now.getHours()
vat _html = '';

_html =  '<p class=&quot;mainheader&quot;>AS IPT Games</p>';
_html += '<p class=&quot;subheader&quot;>Here are some games to play on your lunch break only!</p>';
_html += '<font class=&quot;maintext&quot;>';
_html += '<p>You will need a current IGS account to make use of this facility:</p>';
_html += '<p><a href =&quot;[URL unfurl="true"]http://www.javascript-games.org/card/solitaire/&quot;[/URL] target=&quot;games&quot;>Solitaire</a></p>';
_html += '<p><a href =&quot;[URL unfurl="true"]http://www.javascript-games.org/arcade/frogger/index.html&quot;[/URL] target=&quot;games&quot;>Frogger</a></p>';
_html += '<p><a href =&quot;[URL unfurl="true"]http://www.javascript-games.org/strategy/cbomb/index.html&quot;[/URL] target=&quot;games&quot;>Balls</a></p>';

if (time < 12 || time > 13) 
{
  _html = '<p font class=&quot;maintext&quot;>Please come back between the hours of 12pm and 2pm</p>';
}
document.write(_html);
</script>

All the best,
Jeff
 
surely the || operator is oncorrect.
the aim is to make sure that the links only get dsiplayed between 12 and 2.
if its an or statement then everything before 2 will work, and everything after 12 will work... in other words it wil lalways be displayed, surely?

free, anonymous advice provided by the whole world
 
Exactly. That test over-rides the contents of _html if we are not in the correct time period.

Since we are only looking at the hours component, I tested if it was before 12 hrs OR if it is after 13 hours (since checking for after 14 hours would allow the code to show the links up until 14.59). If it was outside of these hours then prevent the links from showing up.

It was a more elegant way of doing it... well... in my opinion anyway.

It works... try it!

Jeff

 
ahhhh, ofcourse, i left the time as 12 and 14, not 13... no wonder it didnt work. it does now... thanks a lot for your time. i can now be sure that the time we waste playing games is kept to a minimum!

free, anonymous advice provided by the whole world
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top