Javascript DOM HTML IFrame Objects create

Introduction

We can create an <iframe> element via the document.createElement() method:

var x = document.createElement("IFRAME");

Click the button to create an IFRAME element with java2s.com in the frame.

View in separate window

<!DOCTYPE html>
<html>
<body>
<button onclick="myFunction()">Test</button>

<script>
function myFunction() {// www. jav a2  s .c  o m
  var x = document.createElement("IFRAME");
  x.setAttribute("src", "https://www.java2s.com");
  document.body.appendChild(x);
}
</script>

</body>
</html>



PreviousNext

Related