SitePoint Sponsor

User Tag List

Results 1 to 3 of 3

Thread: Convert jQuery function to pure JavaScript

  1. #1
    SitePoint Addict
    Join Date
    Nov 2009
    Posts
    249
    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
    Grüße aus'm Pott
    SitePoint Award Recipient Pullo's Avatar
    Join Date
    Jun 2007
    Location
    Germany
    Posts
    2,486
    Mentioned
    40 Post(s)
    Tagged
    3 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.
    How well do you know your JavaScript from your jQuery?
    Check out SitePoint's latest JavaScript challenge


    My blog

  3. #3
    SitePoint Addict
    Join Date
    Nov 2009
    Posts
    249
    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
  •