1

It's a fairly simple jQuery function but I'm dealing with an iframe which will be displayed on clients' websites who may not be using jQuery. How would this look as pure JS?

$("#pgft-gvway-3xs-iframe").load(function() {
    $(this).height($(this).contents().find("html").height() );
});

UPDATE:

Thanks to everyone who answered. Using a combination of answers I used the following. It did what I needed it to:

 window.addEventListener('load', function(e) {
     var elem= document.getElementById("pgft-gvway-3xs-iframe");
     var insideheight= elem.contentWindow.document.height;
     elem.style.height= insideheight + "px";
 }, false);
Allen S
  • 3,471
  • 4
  • 34
  • 46
  • 1
    [so] is not supposed to operate as a "translate my code" service. What problem exactly are you facing when attempting to convert it to pure JS? Do you understand all of the jQuery functions used? – Lix Aug 11 '13 at 10:18
  • I am not sure wether that is a good idea. Since you seem to be injecting code into client's website - why don't you inject jQuery (CDN), too? – fusio Aug 11 '13 at 10:22
  • Are you sure you wrote whole codes necessary to get your answer? – Super Hornet Aug 11 '13 at 10:22
  • @SuperHornet - yes this is all the code necessary for the function. The function resizes the iframe according to the content within it. – Allen S Aug 11 '13 at 10:25
  • @Lix I'm having problems with how to replicate .load() in pure javascript. Additionally i'm unsure how to manipulate the height of an element using pure JS, or get the height as an integer of a target element. – Allen S Aug 11 '13 at 10:26
  • @Lix I understand the functions used, and what the code does but only on a jQuery level. – Allen S Aug 11 '13 at 10:27
  • @user1775598 - the load event for an iframe is not really something you'd need to ask on [so], neither is the height of an element. I'm 100% sure that there are already [so] questions dealing with these things separately. No need to open a new post for it. – Lix Aug 11 '13 at 10:28
  • +1 for solving it yourself and leaving a note for what worked – Paul Aug 11 '13 at 10:57

2 Answers2

1

As suggested by lix there are already answers for your questions in stack overflow.

For Pure JavaScript on Ready here For Pure JavaScript on height here

Community
  • 1
  • 1
Shanker Paudel
  • 740
  • 1
  • 9
  • 21
0
var elem= document.getElementById("pgft-gvway-3xs-iframe");
var insideheight= elem.contentWindow.document.height;
Super Hornet
  • 2,839
  • 5
  • 27
  • 55
  • What about the load requirements? Your answer is incomplete. – Lix Aug 11 '13 at 10:29
  • @Lix I'm not sure but if you put javascript codes before closing body tag, it would works. – Super Hornet Aug 11 '13 at 10:35
  • Close, it is a [$.load](http://api.jquery.com/load-event/) but it both gets and sets the height of one element from another [$.height](http://api.jquery.com/height/); `insideheight` here is just an intermediate result. – Paul Aug 11 '13 at 10:36