標籤:
A:各種對象的區別:
1、self:當前視窗對象(如果是在iframe裡,則為該架構的視窗對象)
2、top:父視窗對象
3、window:典型情況下,瀏覽器會為每一個開啟的html建立對應的window對象,如果這個文檔包含了多個架構,則瀏覽器會為原始文檔建立一個window對象,再為每個架構建立額外的window對象。可以在當前視窗中直接使用window的全部屬性、方法和集合。
4、location:該對象包含當前url資訊,擁有多個屬性。預設屬性為 location.href,表示整個url,即如果設定location="http://www.ddd.cn",則等同於location.href="http://www.ddd.cn".
B:載入一個新頁面:
1、location.assign("https://www.baidu.com")
2、window.location.href="https://www.baidu.com";
3、window.navigate("https://www.baidu.com"); //只針對IE
4、window.location.replace("https://www.baidu.com"); //window.history.Go(-1);(後退返回)不好使
5、self.location="https://www.baidu.com";
6、top.location="https://www.baidu.com" ;
self.location與top.location的區別:self.location 指的是當前頁面的location,top.location是指當前頁面所屬的父頁面的location。top.location !== self.location ( 有時侯,頁面會被別人的frame引用,含在別人的frame中(有時一些網站因內容不足, 會將別人的頁面當作自己的一個frame,看起來像是自己本身的頁面) 。用此js方法,一旦被別人frame了,會自動彈出。你就不用再擔心了!)//沒試過
7、<meta http-equiv=refresh content=3;URL="https://www.baidu.com">//content=3:3秒後自動跳轉
8、window.history的跳轉方式:history.go(num)//返回第幾頁,也可以使用訪問過的URL,正數向前跳轉,負數向後跳轉
9、window.history.forward()//返回下一頁
10、 history.back()//返回上一頁
C:頁面重新整理:
1、location.reload()
2、 history.go(0)
3、 location=location
4、location.assign(location)
5、document.execCommand(‘Refresh‘) //目前我僅測試到IE支援
6、window.navigate(location) //只針對IE
7、location.replace(location)
8、<meta http-equiv="refresh" content="20"> //每隔20秒自動重新整理
D:location:
location對象表示當前頁面的URL資訊。例如,一個完整的URL:http://www.example.com:8080/path/index.html?a=1&b=2#TOP
可以用location.href擷取。要獲得URL各個部分的值,可以這麼寫:
1、location.protocol; //‘http‘
2、location.port; //‘8080‘
3、location.pathname; //‘/path/index.html‘
4、location.search; //‘?a=1&b=2‘
5、location.hash; //‘TOP‘
E:
document對象屬性:(無則返回空)
1、設定或返回當前文檔有關的cookie:document.cookie;
2、返回當前文檔的網域名稱:document.domain;(讀寫,常用於實現跨域互動)
3、返迴文檔被最後修改的日期和時間:document.lastModified(唯讀)
4、返回載入當前文檔的文檔的 URL:document.referrer
5、返回當前文檔的標題:document.title
6、返回當前的URL:document.URL
以上資訊並不全,僅作為參考。後面會繼續編輯^_^
url、http相關