windows.open window.location.href的用法和區別


window.location.href  只能在當前頁面打開,不能用新窗口打開

windows.open("URL","窗口名稱","窗口外觀設定"); 具體使用參數:http://www.w3school.com.cn/jsref/met_win_open.asp

 

window.open和location.href深入下去,還有以下區別

1.window.location是window對象的屬性,而window.open是window對象的方法

  window.location是你對當前瀏覽器窗口的URL地址對象的參考!  

  window.open是用來打開一個新窗口的函數!

2.window.open不一定是打開一個新窗口!!!!!!!!  

  只要有窗口的名稱和window.open中第二個參數中的一樣就會將這個窗口替換,用這個特性的話可以在iframe和frame中來代替location.href。

如<iframe name="aa"></iframe>  

  <input type=button   onclick="window.open('1.htm','aa','')">和  

  <input type=button  

   onclick="self.frames['aa'].location.href='1.htm'">的效果一樣

3.window.location或window.open如何指定target?

這是一個經常遇到的問題,特別是在用frame框架的時候

解決辦法:

window.location 改為 top.location 即可在頂部鏈接到指定頁

window.open("你的網址","_top");

用戶不能改變document.location(因為這是當前顯示文檔的位置)。

window.location本身也是一個對象。

   但是,可以用window.location改變當前文檔 (用其它文檔取代當前文檔),而document.location不是對象。

   服務器重定向后有可能使document.url變動,但window.location.href指的永遠是訪問該網頁時用的URL.

   大多數情況下,document.location和location.href是相同的,但是,當存在服務器重定向時,document.location包含的是已經裝載的URL,而location.href包含的則是原始請求的文檔的URL.

self.location.href="/url"       當前頁面打開新頁面,與默認的location.href 或者是windows.location.href 或者是 this.location.href 效果一樣

parent.location.href="/url" 在父頁面打開新頁面

 

top.location.href="/url"       在頂層頁面打開新頁面


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM