Create an IFrame Element - Javascript DOM HTML Element

Javascript examples for DOM HTML Element:IFrame

Introduction

You can create an <iframe> element by using the document.createElement() method:

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<body>

<button onclick="myFunction()">create an IFRAME element with java2s.com in the frame</button>

<script>
function myFunction() {//from   w w  w .  j  a v a  2  s  . c om
    var x = document.createElement("IFRAME");
    x.setAttribute("src", "https://www.java2s.com");
    document.body.appendChild(x);
}
</script>

</body>
</html>

Related Tutorials