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

首頁 > 開發 > JS > 正文

淺析location.href跨窗口調用函數

2024-05-06 16:33:03
字體:
來源:轉載
供稿:網友

location.href這個東西常常用于跳轉,location既是window對象的屬性,又是document對象的屬性。

JavaScript hash 屬性 -- 返回URL中#符號后面的內容
JavaScript host 屬性 -- 返回域名
JavaScript hostname 屬性 -- 返回主域名
JavaScript href 屬性 -- 返回當前文檔的完整URL或設置當前文檔的URL
JavaScript pathname 屬性 -- 返回URL中域名后的部分
JavaScript port 屬性 -- 返回URL中的端口
JavaScript protocol 屬性 -- 返回URL中的協議
JavaScript search 屬性 -- 返回URL中的查詢字符串
JavaScript assign() 函數 -- 設置當前文檔的URL
JavaScript replace() 函數 -- 設置當前文檔的URL,并在history對象的地址列表中刪除這個URL
JavaScript reload() 函數 -- 重新載入當前文檔
JavaScript toString() 函數 -- 返回location對象href屬性當前的值
有幾種不同的調用方法,弄到自己有點亂,這次一次性寫個實例,完完全全不再混淆。本次用3個頁面解決問題:

3.html 本窗口:

<html><head><title>js</title><script type="text/javascript" src="jquery-1.6.2.min.js"></script><script type="text/javascript">  $(function(){    $("#parent").click(function(){      parent.location.href = "http://m.survivalescaperooms.com/article/97882.htm";  //父親Iframe被跳轉    })    $("#top").click(function(){      top.location.href = "http://m.survivalescaperooms.com/article/97882.htm";    //爺爺Iframe(最外層)被跳轉    })    $("#self").click(function(){      self.location.href = "http://m.survivalescaperooms.com/article/97882.htm";    //自己跳轉    })    $("#parentparent").click(function(){      parent.parent.location.href = "http://m.survivalescaperooms.com/article/97882.htm";  //爺爺IFrame跳轉,可以獲取到任意層級的父窗口    })  })  function ParentRun()  {    alert("兒子IFrame方法!");  }</script></head><body>我是兒子!<input type="button" id="parent" value="parent.location.href" /><input type="button" id="top" value="top.location.href" /><input type="button" id="self" value="self.location.href" /><input type="button" id="parentparent" value="parentparent.location.href" /></body></html>

2.html 父窗口:

<html><head><title>js??</title><script type="text/javascript" src="jquery-1.6.2.min.js"></script><script type="text/javascript">  $(function(){    $("#Outermost").click(function(){      //判斷當前IFrame是否是最外層頁面      if (top.location == self.location) {        alert("本Iframe是最外層框架");      }      else{        alert("本Iframe不是最外層框架");  //這個被彈出      }    })    $("#Son").click(function(){      //window.frames[0].location = "http://m.survivalescaperooms.com/article/97882.htm";      window.frames["Son"].location = "http://m.survivalescaperooms.com/article/97882.htm";    })    $("#SonFunction").click(function(){      window.frames["Son"].ParentRun();  //IE支持,google發布后)支持(文件系統中不支持)    })    $("#ParentFunction").click(function(){      parent.SonRun();  //IE支持,google發布后支持(文件系統中不支持)    })  })</script></head><body>我是父親!<iframe src="3.html" name="Son" style="width:300px; height:300px;" ></iframe><input type="button" id="Outermost" value="判斷當前IFrame是否最外層" /><input type="button" id="Son" value="控制兒子IFrame跳轉" /><input type="button" id="SonFunction" value="調用子窗口函數"><input type="button" id="ParentFunction" value="調用父窗口函數"></body></html>

1.html 爺窗口:

<html><head><title>js</title><script type="text/javascript" src="jquery-1.6.2.min.js"></script><script type="text/javascript">  $(function(){    alert(window.location == document.location);  //輸出 true  })  function SonRun()  {    alert("爺爺IFrame方法!");  }    //http://localhost:666/1.html?id=1&name=%E5%BC%A0%E4%B8%89#menu  document.write(location.hash + "<br/>");    //  #menu  document.write(location.host + "<br/>");    //  localhost:666  document.write(location.hostname + "<br/>");  //  localhost  document.write(location.pathname + "<br/>");  //  /1.html  document.write(location.port + "<br/>");    // 666  document.write(location.protocol + "<br/>");  // http:  document.write(location.search + "<br/>");    // ?id=1&name=%E5%BC%A0%E4%B8%89  document.write(location.assign + "<br/>");    // function () { [native code] }</script></head><body>我是最爺爺(最外層)!<iframe src="2.html" style="width:500px; height:500px;" ></iframe></body></html>

  三個頁面放在同一個目錄,隨便點下就知道怎么回事了!

  jQuery對IFrame的操作主要是通過

  $("iframe").contents().find("#id1");

  進行跨IFrame操作。

以上就是本文的全部內容,希望對大家有所幫助,謝謝對VeVb武林網的支持!


注:相關教程知識閱讀請移步到JavaScript/Ajax教程頻道。
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 镇赉县| 开化县| 蒲城县| 舞阳县| 新丰县| 资中县| 济南市| 湘西| 沅江市| 繁峙县| 天门市| 镇坪县| 报价| 裕民县| 子长县| 林州市| 江山市| 新晃| 淮南市| 新龙县| 汪清县| 宜川县| 大同市| 明光市| 苗栗县| 襄城县| 固始县| 曲阜市| 金秀| 汶川县| 石阡县| 呈贡县| 江门市| 桐柏县| 肇东市| 克拉玛依市| 文水县| 新余市| 建瓯市| 礼泉县| 盐城市|