核心:
var testiframe=document.getElementById("iframetest").contentWindow;
代码:
<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="UTF-8">
<title></title>
<script type="text/javascript" src="../js/jquery-1.8.3.min.js"></script>
</head>
<body>
<p>屏幕宽度为<span>0</span> px</p>
<p>请试着重新调整浏览器窗口的大小。</p>
<iframe id="iframetest" width="320" height="330" name="aa" frameborder="2" src="../html/wxPictureContentsEdit.html">1111</iframe>
<!--scrolling="no"-->
<script type="text/javascript">
$(document).ready(function(){
function InitialClass(){
$("iframe").css("width","60%");
$("body").css("background","pink");}
/* }*/
InitialClass();
$(window).resize(function() {
var WindowWidth=$(window).width();
$("span").text(WindowWidth);
var brow=$.browser;
var bInfo="";
if(brow.msie){
if(WindowWidth>1250){
$("iframe").css("width","100%");
}else if((900<WindowWidth)&&(WindowWidth<1200)){
$("iframe").css("width","100%");
}else if((400<WindowWidth)&&(WindowWidth<900)){
$("iframe").css("width","100%");
}else if((100<WindowWidth)&&(WindowWidth<300)){
$("iframe").css("width","100%");
}
}
if(brow.mozilla){}
if(brow.safari){}
if(brow.opera){}
});
//滚动监听事件
var testiframe=document.getElementById("iframetest").contentWindow;
var doc=testiframe.document;
/*testiframe.scroll(0,doc.body.scrollHeight);*/
testiframe.addEventListener("scroll",function(e){
alert("111");
return stopDefault(e);
},false)
/* testiframe.οnscrοll= function () {
alert("11111");
}*/
});
/* var testiframe=document.getElementById("iframetest");
console.log(testiframe);
var fun = function(){
alert("333333");
testiframe.removeEventListener("scroll",fun,false);
}
testiframe.addEventListener("scroll",fun,false);*/
</script>
<![endif]-->
</body>
</html>