<!--


    //取3个数字中最大的
	function getBigger(a,  b, c){
     if(isNaN(a)) a = 0;
     if(isNaN(b)) b = 0;
	 if(isNaN(c)) c = 0 ;

     var tmp = Number(a) > Number(b)? a:b;
     return Number(c) > Number(tmp)? c:tmp;
    }

    //取clientHeight, scrollHeight, offsetHeight 中最大的的
	function getBiggestForBodyHeight(myIfrBody){
		if(myIfrBody != null){
			return getBigger(myIfrBody.clientHeight, myIfrBody.scrollHeight, myIfrBody.offsetHeight) ;
		}else return 0;
	}

	
    //自适应高度, 用clientHeight, scrollHeight, offsetHeight 中最大的的
    function suitSelf(myIfrObj){
	      //alert('suitSelf');
	      //alert(myIfrObj.contentWindow.document.body.clientHeight);

		  if(myIfrObj == null) alert(' suitSelf myIfrObj is null');

		  try{
	      var myIfrBody = myIfrObj.contentWindow.document.body;       //contentWindow是为了适应ff
		  if(myIfrBody == null) { //如果iframe页面没有正确加载, body不能获取, 自己设置一个高度
		        alert('suitSelf myIfrBody is null');
				myIfrObj.style.height = 600;
		  }
	       else 
                  myIfrObj.style.height = getBiggestForBodyHeight(myIfrBody);
		  }catch(e){
			  }
	}

    function ifrOnload(myIfrObj){
			   var oldonload = myIfrObj.contentWindow.document.body.onload;  
		   		if (typeof oldonload == 'function') {  
				   oldonload();
                }
				suitSelf(myIfrObj);
				alert('onload') ;
	}

var al = function(){
	alert('alert');};
    //如果不在iframe的onload里面定义方法, 这个方法可以添加iframe 的onload事件, 
	//但是建议在<iframe> 的属性onload里面绑定事件, 这样的兼容性是最好的
	// new function 这个是关键, 如果是function而已, 添加的方法不起作用
 function  suitSelf2(myIfrObj){
	    myIfrObj = myIfrObj == null ? document.getElementById('myIfr_2') : myIfrObj;

		if(myIfrObj == null) alert(' suitSelf2 myIfrObj is null');

		var myIfrBody = myIfrObj.contentWindow.document.body;

		if(myIfrBody == null){  //如果iframe页面没有正确加载, body不能获取, 自己设置一个高度
			 alert('suitSelf2 myIfrBody is null');
			 myIfrObj.style.height = 600;
        }

    //alert(myIfrObj.tagName);
	if (myIfrObj.attachEvent){ //ie
		     alert('assad1');
		     myIfrObj.contentWindow.attachEvent("onload", new function(){ suitSelf(myIfrObj)});  //new 也是必要的, 不过就在这里运行一次而已
		     myIfrObj.contentWindow.attachEvent("onscroll",function(){		//contentWindow必要
			    suitSelf(myIfrObj);
				alert('onscroll');
		   });
		} 
		else if(myIfrObj.contentWindow.addEventListener){  //Mozilla, firefox, 不要在addEventListener直接 suitSelf(myIfrObj);
		    alert('assad2');
			myIfrObj.contentWindow.addEventListener("load", new function(){ suitSelf(myIfrObj);}, false); //new 也是必要的, 不过就在这里运行一次而已
			//alert('myIfrObj.contentWindow: ' + myIfrObj.contentWindow);
			myIfrObj.contentWindow.addEventListener("scroll", function(){    //
			suitSelf(myIfrObj);
			alert('onscroll')}, false);
		}
		else { 
		   alert('assad3');

		   myIfrObj.contentWindow.onload = ifrOnload(myIfrObj);

		   myIfrObj.contentWindow.onscroll = function(){		        
				suitSelf(myIfrObj);
				alert('onscroll');
		   };
		}
        
	}

    

	    //测试用的
	function onL(){
		//alert(document.body.clientHeight);  //ie 856 ff 862 (100%)  , ie 856  ff 862 , 空 iframe  ie 856  ff 862
		//alert(document.body.scrollHeight);  //ie 274 ff 862 (100%) ,  ie 274  ff 862 , 空 iframe  ie 424  ff 862
		var myIfrObj = document.getElementById('myIfr_2');
		if(myIfrObj == undefined){
			alert('myIfrObj2 is null') ;
		}

		suitSelf2(myIfrObj);

		//alert(myIfrObj.contentWindow.onload);

		//alert(myIfr.contentWindow.document.body.clientHeight); // ie 146 ff 150  test6.html
	}

    function gg(){
	 var obj = document.getElementById('myIfr_1');
	 obj.src = 'test6.html'
	}


//-->
