<html>
<head>
<title>浏览器对象</title> <script type="text/javascript">
var a = 20;//声明变量 函数 对象 属于window对象
//alert(window.a);
function test () {
alert("window对象函数"); }
//window.test();//函数调用 </script> </head>
<body>
<div>BOM对象</div> 1.window 消息框 选择框 输入</br>
<script type="text/javascript">
function showMsg() {
var val = window.confirm('你确定吗');//boolean
//alert(val);
if(val ) {
alert("执行完成");
} else {
alert("操作取消");
} }
function showInput() {
var val = window.prompt("请输入密码","不能为空");
// alert(val);
if(val == "123456") {
alert("欢迎你...");
} else {
alert("密码有误...");
} }
</script> <input type="button" value="sayHello" onclick="window.alert('hello')"/>
<input type="button" value="提交" onclick="showMsg()"/> <input type="button" value="密码" onclick="showInput()"/></br> 2.window 定时操作</br>
<script type="text/javascript">
function setExc() {
window.setTimeout("alert('下课了...')", 3000);
}
var ids = null;
function setGo() {
ids = window.setInterval( change, 2000);//函数可以是参数 对象
}
function change () {
var colors = ["red","yellow","blue","green","gray","pink"];
var index = Math.round(Math.random() * 5);
//alert(index);
document.bgColor = colors[index]; }
//change();
function stop () {
if(ids == null) return;
window.clearInterval(ids);
ids = null;
}
</script> <input type="button" value="三秒后执行" onclick="setExc()"/> <input type="button" value="两秒后持续执行" onclick="setGo()"/> <input type="button" value="停止" onclick="stop()"/></br> 3.window 窗口操作</br>
<!-- 在ff/ch 2个浏览器下,窗口对象必须是window.open出来的才可以,默认本地无法执行 -->
<input type="button" value="移动原点" onclick="window.moveTo(0,0)"/>
<input type="button" value="移动" onclick="window.moveBy(10,-10)"/> <input type="button" value="变小" onclick="window.resizeBy(-10,-10)"/>
<input type="button" value="500*500" onclick="window.resizeTo(500,500)"/></br> 4.window 打开新窗体</br>
<script type="text/javascript">
var oWin = null;
function openNew () {
oWin = window.open("内置对象.htm","");//_self _blank }
function controlNew() {
if(oWin == null) return;
oWin.document.bgColor="gray";
}
function closeNew () {
if(oWin == null) return;
oWin.close();
oWin = null;
}
</script>
<input type="button" value="新窗口" onclick="openNew()"/>
<input type="button" value="操作新窗口" onclick="controlNew()"/>
<input type="button" value="关闭新窗口" onclick="closeNew()"/>
<input type="button" value="返回" onclick="history.back()"/> </body> </html>
rs: