最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

javascript - Adjust iframe scroll to height of screen resolution - Stack Overflow

matteradmin4PV0评论

Is it possible to adjust the height of the iframe scroll according to the size of the screen (browser)? It would be like simply replacing the default browser scroll with the iframe scroll. Here is what I mean by this:

I currently have my browser scroll disabled:

<style type="text/css">
html, body {
  overflow: hidden;
}
</style>

I have my iframe:

<iframe width="100%" src="" scrolling="yes" frameborder="0" height="100%">
</iframe>

With width set to 100% the iframe scroll bar is pushed to the far right somewhat replacing the default browser scroll bar and my iframe is now the center piece of the website, (yahoo is an example). I can always adjust the height of the iframe to fit my specific browser size however is there a way I set the iframe scroll according to the browser height automatically? Make it responsive to the browser height just like it is to the width?

Is it possible to adjust the height of the iframe scroll according to the size of the screen (browser)? It would be like simply replacing the default browser scroll with the iframe scroll. Here is what I mean by this:

I currently have my browser scroll disabled:

<style type="text/css">
html, body {
  overflow: hidden;
}
</style>

I have my iframe:

<iframe width="100%" src="http://www.yahoo." scrolling="yes" frameborder="0" height="100%">
</iframe>

With width set to 100% the iframe scroll bar is pushed to the far right somewhat replacing the default browser scroll bar and my iframe is now the center piece of the website, (yahoo is an example). I can always adjust the height of the iframe to fit my specific browser size however is there a way I set the iframe scroll according to the browser height automatically? Make it responsive to the browser height just like it is to the width?

Share Improve this question asked May 13, 2013 at 15:55 NicoNico 1001 gold badge2 silver badges14 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 4

If you're using jQuery, you could do $(window).height() and then set the iframe height to it.

Drop this into the bottom of your HTML file, just above the closing </body> tag.

<script src="//ajax.googleapis./ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script>
;(function($){
    $(document).ready(function(){
        $('iframe').height( $(window).height() );
        $(window).resize(function(){
            $('iframe').height( $(this).height() );
        });
    });
})(jQuery);
</script>
Post a comment

comment list (0)

  1. No comments so far