将jQuery函数转换为纯JavaScript

Translate jQuery function to pure JavaScript

本文关键字:JavaScript 转换 jQuery 函数      更新时间:2023-09-26

这是一个相当简单的jQuery函数,但我要处理的是一个iframe,它将显示在可能没有使用jQuery的客户的网站上。这看起来像是纯JS吗?

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

更新:

感谢所有回答的人。使用答案组合,我使用了以下内容。它做到了我需要的:

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

根据lix的建议,堆栈溢出中已经有了您的问题的答案。

关于Ready上的纯JavaScript,请点击此处对于纯JavaScript在这里的高度

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