如何获取iframe里面和外面的内容

iframe里的内容(父获取子的内容)

//1.
var iframe1 = document.getElementById('iframe1');
//var iframe1 = window.frames["iframe的name值"]
var html1 = .contentWindow.document;
var body1 = .contentWindow.document.body;
//2.
var $iframe1 = $('#iframe1').contents();
var html1 = $iframe1.find('html') ;
var body1 = $iframe1.find('body');

iframe(子获取父的内容)

//1.
var p = window.parent.document;//父的文档
parent.fn();//调用父的方法
parent.hello();//父的变量

原文链接:http://www.helloyoucan.com./article/5a4c48079e859708cc4aa78d

你可能感兴趣的:(如何获取iframe里面和外面的内容)