-1

My application opens in an iframe..

 $(window).scroll(function() { alert("scroll is");});   

if i run this code without iframe it works but with iframe it does not work

Edison Augusthy
  • 1,535
  • 17
  • 32
simba
  • 277
  • 4
  • 19
  • 2
    Possible duplicate of [Scrolling an iframe with javascript?](http://stackoverflow.com/questions/1192228/scrolling-an-iframe-with-javascript) – Mistalis Jan 31 '17 at 10:56
  • Window is the parent window. You need $("iframe").scroll assuming the contents of the iFrame is from the same origin as the script – mplungjan Jan 31 '17 at 10:56
  • 1
    Where did you put this JS code, in the main document (e.g. main.html) or in the iframe document (e.g. iframe.html)? Makes quite a difference. Also, saying "it does not work" is practically never a good description. Does *nothing* happen; do you get errors, does the console show anything? Always try to be clear, specific and complete. – Peter B Jan 31 '17 at 11:04

1 Answers1

0

The following is the content of an HTML file I include in an iFrame, the Javascript gets called correctly. Perhaps compare it to what you have written.

<html>
  <head>
    <title>Test iFrame</title>

    <!-- Add Some Space to Simulate Content (not needed) -->
    <style>
       body {
           width: 100vh;
           height: 100vh;
       }
    </style>
  </head>
  <body>
    <p>iFrame content goes here</p>

    <script type="text/javascript" src="jquery-3.1.1.min.js"></script>
    <script>

      // wait for jQuery to load
      $(document).ready(function() {
          $(window).scroll(function() {
              alert("scroll is");
          });
      });

    </script>
  </body>
</html>
DiscoInferno
  • 142
  • 1
  • 10