Fórum Root.cz
Hlavní témata => Vývoj => Téma založeno: js 19. 09. 2012, 13:26:10
-
Potrebuju v presne dany cas vypsat JavaScriptem text a otevrit novou stranku. Skript tedy pobezi tak dlouho, nez nastane dany cas.
Zkousel jsem:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="cs" lang="cs">
<head>
<meta http-equiv="content-language" content="cs" />
<meta name="language" content="cs" />
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>:-)</title>
</head>
<body>
<script type="text/javascript">
var now = new Date();
var hour = now.getHours();
var minutes = now.getMinutes();
var seconds = now.getSeconds();
var i = 0;
//dany cas:
var hodiny = 13;
var minuty = 19;
var sekundy = 30;
while (i = 0) {
if(hour == hodiny && minutes == minuty && seconds == sekundy) {
document.getElementById("abc").innerHTML="TED<br>";
document.getElementById("abc").innerHTML=":-)";
window.open("http://www.google.cz",'_blank');
i = 1;
}
sleep(500);
delete now;
var now = new Date();
var hour = now.getHours();
var minutes = now.getMinutes();
var seconds = now.getSeconds();
}
</script>
<p id="abc" style="font-size: 150%;"></p>
</body>
</html>
ale porad to nefunguje, nevite, kde delam chybu?
-
A ja si furt rikam, proc mi prohlizec po probuzeni zere 100% procesoroveho casu :-/
Za a) = vs. ==
Za b) man setTimeout
-
Diky za radu. Upravil jsem to, ale stale to nefunguje:
<script type="text/javascript">
function ahojSvete() {
var now = new Date();
var hour = now.getHours();
var minutes = now.getMinutes();
var seconds = now.getSeconds();
var i = 0;
var hodiny = 13;
var minuty = 48;
var sekundy = 40;
while (i == 0) {
if(hour == hodiny && minutes == minuty && seconds == sekundy) {
document.write('TED');
document.getElementById("abc").innerHTML="TED<br>";
document.getElementById("abc").innerHTML=":-)";
window.open("http://www.google.cz",'_blank');
i = 1;
}
sleep(500);
delete now;
var now = new Date();
var hour = now.getHours();
var minutes = now.getMinutes();
var seconds = now.getSeconds();
}
}
function spustit() {
setTimeout('ahojSvete()', 300000); // 5 minut
}
spustit();
ahojSvete();
</script>
-
za B!
javascript nema funkci sleep
-
function test(h, m, s, callback) {
var now = new Date();
var start = new Date();
start.setHours(h, m, s);
setTimeout(callback, start - now);
}
test(14, 15, 0, function() {
document.getElementById("abc").innerHTML="TED<br />:-)";
window.open("http://www.google.cz",'_blank');
});