nayen
January 6, 2013, 6:19am
1
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.
$(function () {
$('#myiframe').on('load', function () {
$('#myiframe').contents().find('body').css('height', '2000px');
})
})
Hi nayen,
Just hook into the iframe’s onload
function:
<!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.
nayen
January 6, 2013, 12:53pm
3
Thank you very much! That worked.