0

i got a phpcode as ill like to have as a javascript code if anyone can help me...
Php code:

<?php 
$now_ho = date("H"); 
//Daytime(6h~19h) 
if ($now_ho < 19){ 
 if ($now_ho >= 6){ 
 $vwimg = "hh_entry_oc1"; 
 } 
} 
//Night (19h~6h) 
if ($now_ho <= 24){ 
 if ($now_ho >= 19){ 
 $vwimg = "hh_entry_oc2"; 
 } 
} 
if ($now_ho < 6){ 
 if ($now_ho >= 0){ 
 $vwimg = "hh_entry_oc2"; 
 } 
} 
?> 
cast.entry.1=<?php echo $vwimg ?>

if you dont understand the code then im looking for a code where you can show a special link at a special time in the day and an other one in the night
ex.
between 6 and 19 the link is www.whatever.com/link1
and between 19 and 6 the link is www.whatever.com/link2

Edited by laursenj: n/a

2
Contributors
12
Replies
14
Views
7 Years
Discussion Span
Last Post by laursenj
0

Hi there,

Perhaps something like this.

<script type="text/javascript">
window.onload = function(){
    var now = new Date();
	var hour = now.getHours();
	var vwimg = "";
	if(hour < 19 & hour >= 6){						//Daytime(6h - 19h) 
		vwimg = "http://www.whatever.com/link1";
	}else if(hour <= 24 & hour >= 19){				//Night (19h - 6h) 
		vwimg = "http://www.whatever.com/link2"; 
	}else if(hour < 6 & hour >=0){
		vwimg = "http://www.whatever.com/link2";
	}
	document.getElementById("linkContainer").innerHTML="<a href='"+vwimg+"'>"+vwimg+"</a>";
}
</script>

Depending on where you'd like the link to appear you'd might want to change the last line (linkContainer) accordingly.

Regards,

Traevel

0

so if i wanna add it as a popup i can just do like this:

<script type="text/javascript">
window.onload = function(){
    var now = new Date();
	var hour = now.getHours();
	var vwimg = "";
	if(hour < 19 & hour >= 6){						//Daytime(6h - 19h) 
		vwimg = "<A onclick="window.open('site1',&#13;&#10;        'Loader','location=yes','resizable=yes','scrollbars=yes');return false;" href="">Loader</A>";
	}else if(hour <= 24 & hour >= 19){				//Night (19h - 6h) 
		vwimg = "<A onclick="window.open('site2',&#13;&#10;        'Loader','location=yes','resizable=yes','scrollbars=yes');return false;" href="">Loader</A>"; 
	}else if(hour < 6 & hour >=0){
		vwimg = "<A onclick="window.open('site2',&#13;&#10;        'Loader','location=yes','resizable=yes','scrollbars=yes');return false;" href="">Loader</A>";
	}
	document.getElementById("linkContainer").innerHTML="<a href='"+vwimg+"'>"+vwimg+"</a>";
}
</script>

or do i need to do that another place??

Edited by laursenj: n/a

0

Change... document.getElementById("linkContainer").innerHTML="<a href='"+vwimg+"'>"+vwimg+"</a>"; into... document.getElementById("linkContainer").innerHTML=vwimg; And I think 'location=yes','resizable=yes','scrollbars=yes' should be 'location=yes,resizable=yes,scrollbars=yes' Although if the attributes of the popup remain the same, you could also place those at the end...

/*snip*/
else if(hour < 6 & hour >=0){
  vwimg = 'site 2';
}
document.getElementById("linkContainer").innerHTML="<A onclick=\"window.open(vwimg, 'Loader','location=yes,resizable=yes,scrollbars=yes');return false;\" href=\"\">Loader</A>";

note: not tested :$ just a quick draft :)

Edited by Traevel: added \ :)

0

the problem is that i got 2 pages... my first one is day_loader.html
and the other one is night_loader.html

can you please make a fully code whit that information in...
i have no clue in how to make a javascript code

1000 x thankyou

0
<script type="text/javascript">
window.onload = function(){
    var now = new Date();
	var hour = now.getHours();
	var vwimg = "";
	if(hour < 19 & hour >= 6){						//Daytime(6h - 19h) 
		vwimg = "day_loader.html";
	}else if(hour <= 24 & hour >= 19){				//Night (19h - 6h) 
		vwimg = "night_loader.html";
	}else if(hour < 6 & hour >=0){
		vwimg = "night_loader.html";
	}
	document.getElementById("linkContainer").innerHTML="<a href='' onClick=\"window.open('" + vwimg + "','Loader','location=yes,resizable=yes,scrollbars=yes');\">Loader</a>";
};
</script>

Add <div id="linkContainer"></div> where you'd like the link to be.

0

okay to get this 100%
i add this code to my website:

<script type="text/javascript">
window.onload = function(){
    var now = new Date();
	var hour = now.getHours();
	var vwimg = "";
	if(hour < 19 & hour >= 6){						//Daytime(6h - 19h) 
		vwimg = "day_loader.html";
	}else if(hour <= 24 & hour >= 19){				//Night (19h - 6h) 
		vwimg = "night_loader.html";
	}else if(hour < 6 & hour >=0){
		vwimg = "night_loader.html";
	}
	document.getElementById("linkContainer").innerHTML="<a href='' onClick=\"window.open('" + vwimg + "','Loader','location=yes,resizable=yes,scrollbars=yes');\">Loader</a>";
};
</script>

and them i add

<div id="linkContainer"></div>

where i need the link?
am i right


sorry for all this confusion

Edited by laursenj: n/a

0

That should work, yes :P

If the <div causes layout trouble you could always turn it into a <span by the way.

0

okay... thankyou VERY much for your help

edit

it just refreshes now
and there is also a { whit the link << got it fixed... it was past of the old script

Edited by laursenj: n/a

0

i need a litle more help now... AGAING

ive tryed evrything i could but i need help to add a picture to the link
the picture addrass is "/images/hotel-button-hotelopen.png" (whitout ")
and the code i got so far (still dont work) is

<a <div id="linkContainer"><IMG src="/images/hotel-button-hotelopen.png"></IMG></div></a>

i can see it arent right so plz help me (again)

Edited by laursenj: n/a

0
<script type="text/javascript">
window.onload = function(){
    var now = new Date();
	var hour = now.getHours();
	var vwimg = "";
	if(hour < 19 & hour >= 6){						//Daytime(6h - 19h) 
		vwimg = "day_loader.html";
	}else if(hour <= 24 & hour >= 19){				//Night (19h - 6h) 
		vwimg = "night_loader.html";
	}else if(hour < 6 & hour >=0){
		vwimg = "night_loader.html";
	}
	document.getElementById("linkContainer").innerHTML="<a href='' onClick=\"window.open('" + vwimg + "','Loader','location=yes,resizable=yes,scrollbars=yes');\"><img src='/images/hotel-button-hotelopen.png' alt='"+vwimg+"'></a>";
};
</script>
<div id="linkContainer"></div>
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.