js_day21--js DOM编程(window对象2)
2014-03-20 15:39
393 查看
Day21
Window对象
clearTimeout()取消由setTimeout()设定的定时器
<html>
<head>
<title>window.test</title>
<script language="javascript" type="text/javascript">
<!--
function test(){
window.alert("abc");
}
var myTimer = setTimeout("test()",3000);
//取消timeout
clearTimeout(myTimer);
//>
</script>
</head>
<body>
</body>
</html>
2.
moveTo()是相当于屏幕的左上角。
moveBy()是相当于当前窗口的左上角。
resizeTo()是把窗口调整到多少。
resizeBy()是相对于当前窗口增加多少。
3.打开新窗口
function test4(){
window. open("day_21_2.html","_self");//self是替换原页面
window.open("day_21_2.html","_blank","resizable=no,menubar=no,width=200,height=100,location=no");//打开一个新的窗口
4.opener返回对创建此窗口的窗口的引用
父窗口和子窗口通信
父窗口:
<html>
<head>
<title>window.test</title>
<script language="javascript" type="text/javascript">
<!--
/*
function test(){
window.alert("abc");
}
var myTimer = setTimeout("test()",3000);
//取消timeout
clearTimeout(myTimer);
*/
/*
function test2(){
window.moveTo(100,100);
window.close();//关闭窗口
}
function test3(){
window.resizeTo(100,100);
}
function test4(){
window. open("day_21_2.html","_self");//self是替换原页面
window.open("day_21_2.html","_blank","resizable=no,menubar=no,width=200,height=100,location=no");//打开一个新的窗口
}
*/
var newWindow;
function test5(){
//newWindow其实就是指向新窗口的引用
newWindow = window.open("day_21_2.html","_blank");
}
function test6(){
newWindow.document.getElementById("info").value=$("info2");
}
function $(id){
return document.getElementById(id).value;
}
//>
</script>
</head>
<body>
我是一个窗口
<!-- <input type="button" value="移动" onclick="test2()"/>
<input type="button" value="改变大小" onclick="test3()"/>
<input type="button" value="打开新窗口" onclick="test4()"/>
-->
<input type="button" value="打开新窗口" onclick="test5()"/>
<span id="mySpan">消息</span>
<input type = "text" id="info2" />
<input type = "button" value="通知子窗口" onclick="test6()" />
</body>
</html>
子窗口:
<script language = "javascript">
function notify(){
var val = document.getElementById("info").value;
window.alert(val);
opener.document.getElementById("mySpan").innerText=val;
}
</script>
我是新窗口
<input type="text" id="info"/>
<input type = "button" value="通知给父窗口" id="info" onclick = "notify()"/>
注意:有些浏览器可能由于安全考虑并不支持这样的通信。
5.
案例:实现登录验证,并且倒计时跳转
登录界面:
<html>
<head>
<title>
登录
</title>
<script language="javascript" type="text/javascript">
function check(){
if($("uname").value=="Gavin"&&$("pwd").value =="123"){
//window.alert("OK");
return true;
} else{
window.alert("用户名或密码错误");
$("uname").value="";
$("pwd").value="";
return false;
}
}
function $(id){
return document.getElementById(id);
}
</script>
</head>
<body>
<form action="Ok.html">
Name:<input type ="text" id="uname"/></br>
Pass:<input type ="password" id="pwd"/></br>
<input type="submit" value="登录" onclick="return check();"/>
<input type="reset" value="重置"/>
</form>
</body>
</html>
登录成功:
Day21
Window对象
clearTimeout()取消由setTimeout()设定的定时器
<html>
<head>
<title>window.test</title>
<script language="javascript" type="text/javascript">
<!--
function test(){
window.alert("abc");
}
var myTimer = setTimeout("test()",3000);
//取消timeout
clearTimeout(myTimer);
//>
</script>
</head>
<body>
</body>
</html>
2.
moveTo()是相当于屏幕的左上角。
moveBy()是相当于当前窗口的左上角。
resizeTo()是把窗口调整到多少。
resizeBy()是相对于当前窗口增加多少。
3.打开新窗口
function test4(){
window. open("day_21_2.html","_self");//self是替换原页面
window.open("day_21_2.html","_blank","resizable=no,menubar=no,width=200,height=100,location=no");//打开一个新的窗口
4.opener返回对创建此窗口的窗口的引用
父窗口和子窗口通信
父窗口:
<html>
<head>
<title>window.test</title>
<script language="javascript" type="text/javascript">
<!--
/*
function test(){
window.alert("abc");
}
var myTimer = setTimeout("test()",3000);
//取消timeout
clearTimeout(myTimer);
*/
/*
function test2(){
window.moveTo(100,100);
window.close();//关闭窗口
}
function test3(){
window.resizeTo(100,100);
}
function test4(){
window. open("day_21_2.html","_self");//self是替换原页面
window.open("day_21_2.html","_blank","resizable=no,menubar=no,width=200,height=100,location=no");//打开一个新的窗口
}
*/
var newWindow;
function test5(){
//newWindow其实就是指向新窗口的引用
newWindow = window.open("day_21_2.html","_blank");
}
function test6(){
newWindow.document.getElementById("info").value=$("info2");
}
function $(id){
return document.getElementById(id).value;
}
//>
</script>
</head>
<body>
我是一个窗口
<!-- <input type="button" value="移动" onclick="test2()"/>
<input type="button" value="改变大小" onclick="test3()"/>
<input type="button" value="打开新窗口" onclick="test4()"/>
-->
<input type="button" value="打开新窗口" onclick="test5()"/>
<span id="mySpan">消息</span>
<input type = "text" id="info2" />
<input type = "button" value="通知子窗口" onclick="test6()" />
</body>
</html>
子窗口:
<script language = "javascript">
function notify(){
var val = document.getElementById("info").value;
window.alert(val);
opener.document.getElementById("mySpan").innerText=val;
}
</script>
我是新窗口
<input type="text" id="info"/>
<input type = "button" value="通知给父窗口" id="info" onclick = "notify()"/>
注意:有些浏览器可能由于安全考虑并不支持这样的通信。
5.
案例:实现登录验证,并且倒计时跳转
登录界面:
<html>
<head>
<title>
登录
</title>
<script language="javascript" type="text/javascript">
function check(){
if($("uname").value=="Gavin"&&$("pwd").value =="123"){
//window.alert("OK");
return true;
} else{
window.alert("用户名或密码错误");
$("uname").value="";
$("pwd").value="";
return false;
}
}
function $(id){
return document.getElementById(id);
}
</script>
</head>
<body>
<form action="Ok.html">
Name:<input type ="text" id="uname"/></br>
Pass:<input type ="password" id="pwd"/></br>
<input type="submit" value="登录" onclick="return check();"/>
<input type="reset" value="重置"/>
</form>
</body>
</html>
登录成功:
<html> <head> <title> 登录 </title> <script language="javascript" type="text/javascript"> var time=5; function jump(){ var string = document.getElementById("mySpan"); string.innerText = "登录成功,"+(time--)+"秒后自动跳转到管理页面!"; if(time==-1){ window.open("manage.html","_self"); } } window.setInterval("jump()",1000); </script> </head> <body> <span id="mySpan"></span> </body> </html>
相关文章推荐
- js_day22--js DOM编程(window对象3+猜拳游戏)
- JS DOM编程 window对象
- js_day20--js DOM编程(window对象1)
- JS DOM操作(三) Window.docunment对象——操作属性
- JS对象字面值编程--动态DOM框架例子
- dom编程中window对象的setInterval,setTimeout方法详解
- js编程思路--给网站定义一个全局的js对象,放到window对象中
- js_day26--js DOM编程(forms/form对象+table对象)
- JS DOM操作(四) Window.docunment对象——操作内容
- JS DOM操作(五) Window.docunment对象——操作元素
- DOM编程之window对象
- JavaScript DOM编程基础精华01(DOM入门,DOM模型和获取页面元素,事件,window对象的方法)
- js_day25--js DOM编程(style对象之 坦克大战转向+切换菜单效果)
- JavaScript DOM编程基础精华01(DOM入门,DOM模型和获取页面元素,事件,window对象的方法)
- 韩顺平 javascript教学视频_学习笔记27_dom对象(window对象3.history.location.navigator.screen.event)_js事件驱动编程
- JS DOM操作(二) Window.docunment对象——操作样式
- Dom编程(Window 对象)
- JavaScript DOM编程基础精华02(window对象的属性,事件中的this,动态创建DOM,innerText和innerHTML)
- js学习--DOM操作详解大全二(window对象)
- (二) DOM编程和Window对象