SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Addict
    Join Date
    Nov 2009
    Posts
    310
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Convert jQuery function to pure JavaScript

    Hi,

    How can I convert the following jQuery function to pure JavaScript? Purpose: so that I will not need to include jQuery file in the header. I tried a couple of things but it didn't work.

    Code:
    $(function () {
    	$('#myiframe').on('load', function () {
    		$('#myiframe').contents().find('body').css('height', '2000px');
    	})
    })

  2. #2
    Gre aus'm Pott gold trophysilver trophybronze trophy
    Pullo's Avatar
    Join Date
    Jun 2007
    Location
    Germany
    Posts
    5,941
    Mentioned
    215 Post(s)
    Tagged
    12 Thread(s)
    Hi nayen,

    Just hook into the iframe's onload function:

    HTML Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
      <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <title>Iframe Example</title>
      </head>
      
      <body>
        <iframe src="iframe.html" id='myiframe'></iframe>
        
        <script>
          var i = document.getElementById("myiframe");
          i.onload = function() {
            this.contentWindow.document.body.style.height = '2000px';
          };
        </script>
      </body>
    </html>
    Hope that helps.

  3. #3
    SitePoint Addict
    Join Date
    Nov 2009
    Posts
    310
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thank you very much! That worked.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •