Javascript倒计时计时器与新窗口
Javascript Countdown Timer with New Window
我真的不知道javascript,但我黑在一起(即发现)下面的代码,正是我想要的,除了,我希望窗口焦点结束在一个倒计时计时器。换句话说,我想打开yahoo.com窗口,但不想把它放在焦点上。
编辑:我只需要这个在IE11中工作。
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<script language='JavaScript'>
var time = 10;
var page = "http://google.com";
function countDown(){
time--;
gett("container").innerHTML = time;
if(time == -1){
window.location = page;
}
}
function gett(id){
if(document.getElementById) return document.getElementById(id);
if(document.all) return document.all.id;
if(document.layers) return document.layers.id;
if(window.opera) return window.opera.id;
}
function init(){
if(gett('container')){
setInterval(countDown, 1000);
gett("container").innerHTML = time;
}
else{
setTimeout(init, 50);
}
}
document.onload = init();
window.open('http://www.yahoo.com');
</SCRIPT>
</head>
<body>
<H2>Google loading in <span id="container"></span> seconds...</H2>
</body>
</html>
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<script language='JavaScript'>
var time = 10;
var page = "http://google.com";
function countDown(){
time--;
gett("container").innerHTML = time;
if(time == -1){
window.open('http://www.yahoo.com',"_blank","toolbar=yes, scrollbars=yes, resizable=yes, top=500, left=500, width=400, height=400");
}
}
function gett(id){
if(document.getElementById) return document.getElementById(id);
if(document.all) return document.all.id;
if(document.layers) return document.layers.id;
if(window.opera) return window.opera.id;
}
function init(){
if(gett('container')){
setInterval(countDown, 1000);
gett("container").innerHTML = time;
}
else{
setTimeout(init, 50);
}
}
document.onload = init();
</SCRIPT>
</head>
<body>
<H2>Google loading in <span id="container"></span> seconds...</H2>
</body>
</html>
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body>
<h2>Google loading in <span id="counter">3</span> seconds...</h2>
<script>
document.onload = init()
$elem = document.getElementById("counter");
var timer = $elem.innerHTML;
//timer = 30; //if you want start timer from javascript or change time inside counter
function init() {
var interval = setInterval(function() {
timer = timer-1;
$elem.innerHTML = timer;
if(timer == 0) {
var popWindow = window.open("http://google.com", '_blank', 'location=yes,height=570,width=520,scrollbars=yes,status=yes');
popWindow.blur();
window.focus();
window.onblur = window.focus();
clearInterval(interval);
}
},1000);
}
</script>
</body>
</html>
相关文章:
- 防止Iframe窗体在新窗口中打开
- 在新窗口上使用d3.js
- 按下一个HTML按钮,该按钮使用一个功能在同一个新窗口中打开URL
- asp.net MVC,重定向到视图,视图打开新窗口到外部url,它'It’’’’我们被当成一种风景
- 如何在新选项卡中而不是在新窗口中打开URL
- 如何禁用鼠标中键单击超链接以在新选项卡或新窗口中打开
- 如何打开一个新窗口或选项卡,并将其提供给javascript执行
- window.open:是否可以通过修改DOM来打开一个新窗口
- Chrome应用程序在全屏中创建新窗口-html元素不是全高的
- 如何在windowsphone 7浏览器中通过javascript打开新窗口或选项卡
- 为在新窗口中打开外部链接创建异常
- 如何使用base64 PDF内容打开新窗口
- 在后台打开新窗口
- 在新窗口中通过谷歌地图的localStorage作为地图中心
- javascript window.open(),并在新窗口中搜索DOM
- 打开一个新窗口并更改其父窗口'的内容
- 在Firefox restartless插件中,当一个新窗口打开时,我如何运行代码(监听窗口打开)
- SVG编辑链接获胜't在新窗口中打开
- 如何通过单击数据在新窗口上显示TableView数据
- 打开新窗口进行打印时不显示 JavaScript 图像