Window对象
1.alert(“文本内容”):警告框(window中的方法),出现时,用户需要点击确定才能继续进行操作。一般在javascript学习时经常用,相当于java中的System.out.println()语句。
<head>
<script type="text/javascript">
alert("这是window的alert方法");
//等价于window.alert(“这是window的alert方法”);
</script>
</head>
2.confirm(“文本内容”):确认框(window中的方法),用于使用户可以验证或接受某些信息。当确认框出现后,用户需要点击确定或者取消按钮才能继续进行操作。如果用户点击确认,那么返回值为true,如果点击取消,返回值为null。
<head>
<script type="text/javascript">
confirm("这是window的confirm方法");
//等价于window.confirm("这是window的confirm方法");
</script>
</head>

3.prompt(“文本内容”,”默认值”):提示框(window中的方法),用于提示用户进入页面前输入某个值,当提示框出现后,用户需要输入某个值,然后点击确认或取消按钮后才可以继续操作。如果点击q确认那么返回值为输入的值,点击取消返回值为null.
<head>
<script type="text/javascript">
prompt("这是window的prompt方法","这里是默认值");
</script>
</head>

4.open(“http://www.baidu.com”,”_blank”,””,””):打开新窗口(window中的方法),当在浏览器预览这个html时,会立即弹出另外一个窗口;参数:第一个参数是指定要打开的网址;第二个参数是,以什么形式打开一个网页;第三个参数是指定新打开的网页都有那些东西,地址栏啊,滚动条啊...第四个参数是结合第二个参数使用的,如果新打开的网页时同一个网页,是true的话会替换了原来窗口的历史数据,是false则不替换。
<head>
<script type="text/javascript">
window.open("http://www.baidu.com","_parent","height=400,width=600,location=no, menubar=no, resizable=no, scrollbars=no, status=no, titlebar=no, toolbar=no, ",false);
</script>
</head>
5.onload:当浏览器完成对象的装载后立即触发的事件(window中的事件),只有点击确定后才可以正常浏览网页。还有其它的事件如:onunload(关闭窗口后弹出的窗口)、onbeforeunload(关闭窗口前弹出的窗口)....
<script type="text/javascript">
window.οnlοad=function()
{
alert("这是onload事件触发的窗口");
}
</script>

6.window对象中navigator对象的相关操作:
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
<script type="text/javascript">
window.οnlοad=function()
{
var name=window.navigator.appName;//获取浏览器名称
var version=window.navigator.appVersion;//获取浏览器的版本等信息
alert(name+"..........."+version);
}
</script>
</head>
<body>
</body>

7.window对象中location对象的操作:
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
<script type="text/javascript">
window.οnlοad=function()
{
var url = window.location.href;
alert(url);//获取当前window.html在硬盘中的位置
//设置url的值
//url=window.location.href="http://www.baidu.com";
//alert(url);
}
</script>
</head>
<body>
</body>

8.window对象中的event对象的操作:最主要的是keyCode\returnValue\srcElement三个方法。
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
<script type="text/javascript">
function keyDemo()
{
//alert(window.event.keyCode);//打印相关字符对应码表例如0-9打印的是48-57,a-z打印的是97-122
/*
if(!(window.event.keyCode>=48&&window.event.keyCode<=57))
{
alert("您输入的不是数字");
window.event.returnValue=false;
}
*/
//获取事件源对象
var src=event.srcElement;
alert(src.type);//结果是text
}
</script>
</head>
<body>
<input type="text" οnkeypress="keyDemo()"/>
</body>
