Javascript Element How to - Update an iframe for a new URL








Question

We would like to know how to update an iframe for a new URL.

Answer


<!DOCTYPE html>
<html>
<head>
</head><!--   w ww  .j  av a2 s . c o m-->
<body>
  <iframe src="" id="logviewer"></iframe>
  <script type="text/javascript">
    document.getElementById('logviewer').src = "http://www.cnn.com";
    console.log('Loaded Yahoo');
</script>
</body>
</html>

The code above is rendered as follows: