1.window对象

1.1 window对象

window对象是BOM的核心、window对象指当前的浏览器窗口

所有JavaScript全局对象 、函数以及变量均自动成为window对象的成员

全局变量是window对象的属性

全局函数是window对象的方法

甚至HTML DOM的document也是window对象属性之一

1.2 window.innerHeight  浏览器窗口的内部高度

window.innerWidth  浏览器窗口的内部宽度

Window.html

 <!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
</head>
<body>
<button id="btn" onclick="btnClicked()">按钮</button><br />
<script>
document.write("宽度:"+window.innerWidth+",高度:"+window.innerHeight); function btnClicked(){
window.open("index.html","windowname","height=200,width=200,top=100,left=100,toolbar=no,menubar=no");//打开页面设置各属性
window.close();//关闭页面
}
</script>
</body>
</html>

2.计时器

2.1 计时事件

通过使用JavaScript,我们可以做到在一个设定的时间间隔之后来执行代码,而不是在函数被调用后立即执行,称之为计时事件。

2.2 计时方法

1>setInterval()  间隔指定的毫秒数不停的执行指定的代码

clearInterval()  方法用于停止setInterval()方法执行的函数代码

2>setTimeout()  暂停指定的毫秒数后执行指定的代码

clearTimeout()  方法用于停止执行setTimeout()方法的函数代码

JiShiQi.html

 <!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
</head>
<body>
<p id="ptime"></p>
<button id="btn" onclick="stopTime()">stopTime()</button><br />
<button id="btn" onclick="myWin()">myWin()</button><br />
<button id="btn" onclick="myWinXh()">myWinXh()</button><br />
<button id="btn" onclick="stopWin()">stopWin()</button><br />
<script>
var mytime=setInterval(function(){ //不断的执行,1秒刷新
getTime()
},1000);
function getTime(){
var d=new Date();
var t=d.toLocaleTimeString();
document.getElementById("ptime").innerHTML=t;
}
function stopTime(){ //停止执行
clearInterval(mytime);
} var win;
function myWin(){
win=setTimeout(function(){ //指定3秒后弹出
alert("hello");
},3000);
} var winXh;
function myWinXh(){
alert("hello");
win=setTimeout(function(){ //指定3秒后循环弹出
myWinXh();//自己调用自己循环
},3000);
} function stopWin(){ //终止win弹出
clearTimeout(win);
} </script>
</body>
</html>

3.History对象

3.1 History对象

window.history对象包含浏览器的历史(url)的集合

3.2 History方法

history.back()  与在浏览器点击后退按钮相同

history.firward()  与在浏览器点击向前按钮相同

history.go()  进入历史中的某个页面

index.html

 <!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title></title>
</head>
<body>
<!--<a href="History.html">跳转到History</a>
<button id="btn" onclick="goHistory()">goHistory()</button>
<script>
function goHistory(){
history.forward(); //前进到下个页面
}
</script>--> <a href="History.html">跳转到History</a>
</body>
</html>

History.html

 <!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
</head>
<body>
<!-- <button id="btn" onclick="goindex()">goindex()</button>
<script>
function goindex(){
history.back(); //后退回上一页面
}
</script>
--> <br />
<form>
<input type="text" id="username" />
</form>
<button id="btn" onclick="safe()">登录</button>
<script>
function safe(){
var name=document.getElementById("username").value;
if(name=="hello"){
history.go(-1); //进入前页面,当前页面为0
}else{
alert("输入错误");
}
}
</script>
</body>
</html>

4.Location对象

4.1 Location对象

window.location对象用于获得当前页面的地址(url),并把浏览器重定向到新的页面。

4.2 Location对象的属性

location.hostname 返回web主机的域名

location.psthname  返回当前页面的路径和文件名

location.port  返回web主机的端口

location.protocol  返回所使用的web协议(http://或https://)

location.href  属性返回当前页面的URL

location.assign()  方法加载新的文档

Location.html

 <!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
</head>
<body>
<button id="btn1" onclick="get1()">gethostname</button>
<p id="p1"></p>
<script>
function get1(){
document.getElementById("p1").innerHTML=window.location.hostname;
}
</script> <button id="btn2" onclick="get2()">getpathname</button>
<p id="p2"></p>
<script>
function get2(){
document.getElementById("p2").innerHTML=window.location.pathname;
}
</script> <button id="btn3" onclick="get3()">getport</button>
<p id="p3"></p>
<script>
function get3(){
document.getElementById("p3").innerHTML=window.location.port;
}
</script> <button id="btn4" onclick="get4()">gethref</button>
<p id="p4"></p>
<script>
function get4(){
document.getElementById("p4").innerHTML=window.location.href;
}
</script> <button id="btn5" onclick="get5()">getassign</button>
<p id="p5"></p>
<script>
function get5(){
location.assign("http://www.baidu.com");//方法加载新的文档
}
</script> </body>
</html>

5. screen对象

5.1 Screen对象

window.screen对象包含有关用户屏幕的信息

5.2 属性

screen.availWidth  可用的屏幕宽度

screen.availHeight  可用的屏幕高度

screen.Height  屏幕高度

screen.Width  屏幕宽度

Screen.html

 <!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
</head>
<body>
<script>
document.write("可用宽度:"+screen.availWidth+", 可用高度:"+screen.availHeight);
document.write("<br />");
document.write("宽度:"+screen.width+", 高度:"+screen.height);
</script>
</body>
</html>

JS 浏览器对象的更多相关文章

  1. Js浏览器对象

    Js浏览器对象——window对象 1.window对象: (1)window对象是BOM的核心,window对象指当前的浏览器窗口. (2)所有的JavaScript全局对象.函数以及变量均自动成为 ...

  2. JS浏览器对象:window对象、History、Location对象、Screen对象

    一.JS浏览器对象-window 1.window对象 window对象是BOM的核心,window对象指当前的浏览器窗口 所有JavaScript全局对象.函数以及变量均自动成为window对象的成 ...

  3. js浏览器对象的属性和方法

    1.window对象 /*1.计算浏览器窗口大小*/ //不算滚动条: var width = window.innerWidth; var height = window.innerHeight; ...

  4. js浏览器对象navigator

    移动端通常需要判断当前设备的类型,比如安卓,ios等.输出浏览器的请求代理,可以判断浏览器类型.js代码如下 判断当前浏览器的请求代理 我是出来玩的! <!DOCTYPE html> &l ...

  5. JS浏览器对象-window对象

    代码: <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title ...

  6. JS浏览器对象-Screen对象

    代码: <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title ...

  7. JS浏览器对象-Location对象

    1.返回web主机的域名 <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> ...

  8. JS浏览器对象-History对象

    <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...

  9. JS浏览器对象-计时器

    setInterval用法 <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> ...

随机推荐

  1. win10中打开SQL Server配置管理器方法

    使用 Windows10 访问 SQL Server 配置管理器 因为 SQL Server 配置管理器是 Microsoft 管理控制台程序的一个管理单元而不是单独的程序,所以,当运行 Window ...

  2. mysql数据导入的时候提示Got a packet bigger than 'max_allowed_packet' bytes

    Got a packet bigger than 'max_allowed_packet' bytes错误 默认可能是2M 把max_allowed_packet设置大于5M试试,我设置为160M,输 ...

  3. 【好文转帖】控制反转(IOC)和依赖注入(DI)的区别

    IOC   inversion of control  控制反转 DI   Dependency Injection  依赖注入 要理解这两个概念,首先要搞清楚以下几个问题: 参与者都有谁? 依赖:谁 ...

  4. 2 数据库开发--MySQL下载(windows)

    Windows:(mysql) 操作: 0.下载安装mysql www.mysql.org downloads->进入社区community community 5.7.21 下载5.6 Mic ...

  5. 14 并发编程-(协程)-greenlet模块&gevent模块

    1.实现多个任务之间进行切换,yield.greenlet都没有实现检测I/O,greenlet在实现多任务切换下更简单 from greenlet import greenlet def eat(n ...

  6. C语言高级程序设计——进制算法以及位算符号

    语言不够官方:意会: 数据储存运算是以二进制的,二进制数有原码 反码 补码三种.通常所说的二进制就是原码.(语言不官方) 原码 :4的原码可以为:0000 0100:最高位0 可以为符号数 反码:正数 ...

  7. java多线程启动的方法runnable和callable

  8. soapUI参数中文乱码问题解决方法&soap UI工具进行web接口测试

    soapUI参数中文乱码问题解决方法 可能方案1: 字体不支持中文,将字体修改即可: file-preferences-editor settings-select font 修改字体,改成能显示中文 ...

  9. leetcode 20 Valid Parentheses 有效的括号

    描述: 给定一些列括号,判断其有效性,即左括号有对应的有括号,括号种类只为小,中,大括号. 解决: 用栈. bool isValid(string s) { stack<char> st; ...

  10. 4-在windon10上mysql安装与图形化管理

    安装及可能遇到的问题: 1.windows10上安装mysql(详细步骤  https://blog.csdn.net/zhouzezhou/article/details/52446608 2. 在 ...