在iframe父界面獲取iframe裏面的標籤

上一篇裏邊介紹了在裏邊利用iframe引入另外一個html導航文件,有興趣的朋友能夠看一看 http://www.cnblogs.com/simba-lkj/p/6031662.htmlhtml

目前遇到一些問題們,想要在引用了iframe的文件裏修改iframe裏邊的樣式。jquery

解決了這個問題,整理一下,供你們參考數組

demo:spa

<div class="iframe">htm

<iframe src="header.html" width="100%" height="442px" marginwidth="0" frameborder="no" scrolling="no"></iframe>blog

</div>rem

一、這是我首先考慮的一個方法get

獲取iframe引入的html文件元素經過id獲取iframe

要在網頁加載完以後再進行這段代碼 
window.onload = function(){
 var test = document.getElementById('iframe的id').contentWindow.document.getElementById('iframe裏要獲取的元素的id');
 console.log(test);
 test.style.display = "none";
}
 
二、能夠在iframe文件js裏獲取父網頁的相對路徑,將相對路徑存儲在一個數組中,經過判斷相對路徑 來進行操做

實例:it

 

var URL  = window.parent.location.pathname;

路徑數組:

var arrURL = ["/CASE/aishuoke/index.html","/CASE/aishuoke/about.html","/CASE/aishuoke/news.html","/CASE/aishuoke/download.html","/CASE/aishuoke/case.html","/CASE/aishuoke/job.html","/CASE/aishuoke/shownews.html",

"/CASE/aishuoke/showinfo.html","/CASE/aishuoke/showimg_first.html","/CASE/aishuoke/showimg_second.html","/CASE/aishuoke/showimg_third.html","/CASE/aishuoke/showimg_forth.html"];

 

switch (URL){

 

case arrURL[0]:

 

$("#shouye").addClass("show").siblings().removeClass("show");

 

break;

}

 

 
總結:

在iframe中獲取父窗口的元素

$('#父窗口中的元素ID', parent.document).click();jquery

在父窗口中獲取iframe中的元素 

一、:var test = $("#iframe的ID").contents().find("#iframe中的控件ID");//jquery 方法1 

  var test2 =  $("#iframe中的控件ID",document.frames("frame的name").document);//jquery 方法2

  var test3 = document.getElementById('iframe的id').contentWindow.document.getElementById('iframe裏要獲取的元素的id');//js方法
 
 轉載請註明出處,謝謝合做*-* http://www.cnblogs.com/simba-lkj/p/6032458.html
相關文章
相關標籤/搜索