How does iframe ready Method Work in jQuery



Here’s an example wherein the iframe size is larger than the page. We will scroll to the top of the page whenever the iframe loads using jQuery −

Example

Live Demo

<!DOCTYPE html>
<html>
  <head>
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
    <script>
    $(document).ready(function(){
      $("button").click(function(){
        $('iframe').ready(function(){
          $(window).scrollTop(0);
        });
      });
   });
   </script>
  </head>
<body>
  <iframe frameborder="2" height="900" id="iframe" align="top" src="https://www.qries.com" width="900" ></iframe><br>
  <button>Loop through each image</button>
</body>
</html>
Updated on: 2020-06-20T07:24:24+05:30

3K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements