[ASP.NET][JavaScript] 取得iframe內的路徑

  • 2533
  • 0
  • 2013-07-23

[ASP.NET][JavaScript] 取得iframe內的路徑

沒在用 iframe 才會有這個問題 =.="

一開始以為取得 iframe 中的 src就可以了

後來才知道,當 iframe 頁面切換時,想獲得 iframe 內

的路徑,應該在 document 的 frames 去找尋

取得的方法大同小異


this.contentWindow.location
window.frames[0].location
window.frames["iframe01"].location
frames[0].location
$("#iframe01").get(0).contentWindow.location  //JQuery取得iframe

 

附上一些屬性的對照

host localhost:2138
hostname localhost
href http://localhost:2138/IFrameDemo/ContentPage/Default3.aspx
origin http://localhost:2138
pathname /IFrameDemo/ContentPage/Default3.aspx
port 2138
protocol http:

 

一些測試,方框內是 iframe 由 button 切換

image

 

 

切換頁面會判斷路徑是否第四頁,第四頁的話 iframe 會變成空

image

 

範例檔案 下載