質問

I am using this script to resize iframe height and width automatically based on the content..

<script language="JavaScript">


function autoResize(id){
    var newheight;
    var newwidth;

    if(document.getElementById){
        newheight=document.getElementById(id).contentWindow.document .body.scrollHeight;
        newwidth=document.getElementById(id).contentWindow.document .body.scrollWidth;
    }

    document.getElementById(id).height= (newheight) + "px";
    document.getElementById(id).width= (newwidth) + "px";
}
</script>

Calling this function in Iframe onload..

<iframe src="index.htm" scrolling='no'  width="100%" height="100%" name="CHANGETHIS" id="CHANGETHIS" marginheight="0" frameborder="0" onLoad="autoResize('CHANGETHIS');"></iframe>

Consider I am using hyperlink <a href="index2.htm">Redirect</a>

If I click Redirect hyperlink, it is redirecting to index2.htm file with iframe auto resize based on the content. If I go back (browser back or back button) to the previous page (index.htm), iframe auto resize is not working only in firefox..It is working fine in IE..

Is there any solution for this to work also in firefox using javascript or jquery?

役に立ちましたか?

解決

Use this: onresize="autoResize('CHANGETHIS');"

<iframe src="index.htm" scrolling='no'  width="100%" height="100%" name="CHANGETHIS" id="CHANGETHIS" marginheight="0" frameborder="0" onload="autoResize('CHANGETHIS');" onresize="autoResize('CHANGETHIS');"></iframe>
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top