国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 語言 > JavaScript > 正文

javascript學習筆記(十四) window對象使用介紹

2024-05-06 14:21:45
字體:
來源:轉載
供稿:網友
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. ; //同上
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) {
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表

圖片精選

主站蜘蛛池模板: 富源县| 勐海县| 双桥区| 天长市| 伊川县| 米易县| 高平市| 抚顺县| 宕昌县| 新晃| 北辰区| 五大连池市| 耿马| 临沧市| 科尔| 公安县| 江华| 秀山| 荆门市| 全州县| 门源| 西宁市| 二连浩特市| 清远市| 平昌县| 南澳县| 凤翔县| 罗甸县| 即墨市| 启东市| 安义县| 常宁市| 克山县| 金平| 磐安县| 宁河县| 上栗县| 洪江市| 万宁市| 惠东县| 安化县|