1
2
3
4
5
6
7
8
9
10
11
12
|
<
iframe
src
=
"http://www.baidu.com/web/liuyan"
id
=
"ifrm"
onload
=
"loadFrame(this)"
frameborder
=
"0"
scrolling
=
"no"
width
=
"71%"
height
=
"1500"
></
iframe
>
<
script
type
=
"text/javascript"
>
function loadFrame(obj){
$('html, body').animate({
scrollTop: $("#ifrm").offset().top
}, 1);
}
window.addEventListener('message',function(e){
alert(e.data);
},false);
</
script
>
|
对应的iframe页面
1
2
3
4
5
6
7
8
9
10
11
|
<
div
id
=
"dianjiwo"
>点击我测试</
div
>
<
script
>
$(function(){
//iframe嵌套发送父页面参数
$("#dianjiwo").click(function(){
window.parent.postMessage(1,'*');
});
})
</
script
>
|
本文转自 gutaotao1989 51CTO博客,原文链接:http://blog.51cto.com/taoyouth/1934827