简体   繁体   中英

Translate jQuery function to pure JavaScript

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);

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

var elem= document.getElementById("pgft-gvway-3xs-iframe");
var insideheight= elem.contentWindow.document.height;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM