发布于 2016-10-06 08:08:02 | 144 次阅读 | 评论: 0 | 来源: 网友投递

这里有新鲜出炉的Javascript教程,程序狗速度看过来!

JavaScript客户端脚本语言

Javascript 是一种由Netscape的LiveScript发展而来的原型化继承的基于对象的动态类型的区分大小写的客户端脚本语言,主要目的是为了解决服务器端语言,比如Perl,遗留的速度问题,为客户提供更流畅的浏览效果。


javascript学习笔记之window对象使用介绍,需要的朋友可以参考下
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 () { 
//执行某些操作 
} 


最新网友评论  共有(0)条评论 发布评论 返回顶部

Copyright © 2007-2017 PHPERZ.COM All Rights Reserved   冀ICP备14009818号  版权声明  广告服务