作家
登录

javascript学习笔记(十四) window对象使用介绍

作者: 来源:www.28hudong.com 2013-03-30 00:27:04 阅读 我要评论

1.窗口位置 以下取得浏览器窗口距屏幕左边和上边的位置 复制代码 代码如下: var leftPos = (typeof window.screenLeft == "number") ? window.screenLeft : window.screenX; //左边位置 var topPos = (typeof window.screenTop == "number") ? window.screenTop : window.screenY; //上边位置 2.浏览器大小 以下取得浏览器页面视口的大小 复制代码 代码如下: var pageWidth = window.innerWidth, pageHeight = window.innerHeight; if (typeof pageWidth != "number") { if (document.compatMode == "CSS1Compat") { pageWidth = document.documentElement.clientWidth; pageHeight = document.documentElement.clientHeight; } else { pageWith = document.body.clientWdith; pageHeight = document.body.clientHeight; } } 3.打开或弹出窗口 window.open()方法,可以接受4个参数,通常只需指定第一个参数,第一个参数为URL,第二个参数为_self 、_parent 、_top 、_blank 或者框架名 复制代码 代码如下: window.open("http://www.baidu.com"); window.open("http://www.baidu.com","_blank"); window.open("http://www.baidu.com","topFrame","height=400,width=400,top=10,left=10,resizable = yes"); topFrame.resizeTo(500,300); //调整窗口大小 topFrame.moveTo(100,100); //移动窗口位置 topFrame.close(); //关闭新打开的窗口,IE会报错 4.location 对象 location.href(URL) 加载URL 复制代码 代码如下: location.href(URL) 加载URL location.href("http://www.baidu.com"); location.href = "http://www.baidu.com" ; //同上 location.assign = "http://www.baidu.com"; //同上 window.loaction = "http://www.baidu.com"; //同上 location.replace("http://www.baidu.com"); //同上,但不能回退 location.reload(); //重新加载(可能从缓存中加载) location.reload(true); //重新加载(从服务器中加载) location.search() 返回URL中的查询字符串,字符串以为?开头 5.获取查询字符串参数 复制代码 代码如下: function getQueryStringArgs() { var qs = (location.search.length > 0) location.search.substring(1) : ""; var args ={}; var items = qs.split("&"); var item = null,name = null,value = null; for (var i=0 ; i<items.length ; i++) { item = itmes[i].split("="); name = decodeURIComponent(item[0]); value = decodeURIComponent(item[1]); args[name] = value; } return args; } //假设查询字符串参数是?q=javascript&num=10 var args = getQueryStringArgs(); alert(args["q"]); //"javascript" alert(args["num"]); //"10" 6.history 对象 复制代码 代码如下: history.go()页面跳转 history.go(-1); //后退一页 history.go(1); //前进一页 history.go(2); //前进两页 history.go("baidu.com"); 跳转到最近的baidu.com页面 history.back(); //后退一页 history.forword(); //前进一页 检测当前页是不是用户打开的第一个页面 复制代码 代码如下: if (history.length == 0) { //如果打开的是第一个页面的话,执行某些操作 } 7.页面加载 window.onload() 用于页面加载结束后做某些操作 复制代码 代码如下: window.onload = function () { //执行某些操作 }

  推荐阅读

  javascript学习笔记(六) Date 日期类型

1.创建日期对象 复制代码 代码如下: var now = new Date(); //获得当前系统日期和时间 var someDate = new Date(Date.parse("May 25,2012")); var someDate = new Date("May 25,2012"); //与上相同 var someDate =>>>详细阅读


本文标题:javascript学习笔记(十四) window对象使用介绍

地址:http://www.17bianji.com/kaifa2/JS/23312.html

关键词: 探索发现

乐购科技部分新闻及文章转载自互联网,供读者交流和学习,若有涉及作者版权等问题请及时与我们联系,以便更正、删除或按规定办理。感谢所有提供资讯的网站,欢迎各类媒体与乐购科技进行文章共享合作。

网友点评
自媒体专栏

评论

热度

精彩导读
栏目ID=71的表不存在(操作类型=0)