Помогите разобраться с таймером
код такой:
в chrome ошибка такая: cannot call method 'open' of undefined в строке wnd.document.open(); а что не так не пойму, делаю как в видео курсе.. там работает, а у меня нет:( код такой: var timer; var wnd; function showTime() { var now = new Date(); wnd.document.open(); wnd.document.write("<h1 align='center'>"); wnd.document.write (now.toLocaleTimeString()); wnd.document.write ("</h1>"); wnd.close(); } function startClock() { if(!timer) { var top = (screen.height-340)/2; var left = (screen.width-270)/2; var params = "width=300,height=100,top="+top+",left="+left; wnd = window.open('','myClockWindow',params) timer = window.setInterval('showTime()', 1000) } } |
вот так попробуй
var timer;
var wnd;
function showTime()
{ var now = new Date();
wnd.document.open();
wnd.document.write("<h1 align='center'>");
wnd.document.write (now.toLocaleTimeString());
wnd.document.write ("</h1>");
wnd.close();
}
function startClock()
{
if(!timer)
{
var top = (screen.height-340)/2;
var left = (screen.width-270)/2;
var params = "width=300,height=100,top="+top+",left="+left;
wnd = window.open('','myClockWindow',params)
showTime()
timer = window.setInterval(showTime, 1000)
}
}
|
спасибо за ответ ОлегА, новсе равно ошибка в том же самом месте.(wnd.document.open();)
|
так стоп по моему wnd.document.open(); - это здесь вообще лишнее
|
ОлегА,
9 строка убивает окно |
Цитата:
|
:write:
лучше скопировать код и смотреть автономно -- политика запрета всплывающих окон.
<!DOCTYPE HTML>
<html>
<head>
<title>Untitled</title>
</head>
<body>
<script>
var timer;
var wnd;
function showTime()
{ var now = new Date();
wnd.document.open();
wnd.document.write("<h1 align='center'>");
wnd.document.write (now.toLocaleTimeString());
wnd.document.write ("</h1>");
wnd.document.close();
timer = window.setTimeout(showTime, 1000)
}
function startClock()
{
if(!timer)
{
var top = (screen.height-340)/2;
var left = (screen.width-270)/2;
var params = "width=300,height=100,top="+top+",left="+left;
wnd = window.open('','myClockWindow',params)
showTime()
}
}
startClock()
</script>
</body>
</html>
|
Цитата:
|
Цитата:
|
Цитата:
|
| Часовой пояс GMT +3, время: 21:44. |