0

I was wondering if anyone could help me with making a program in HTML that looks like this:

<html>
    <body>
        <script>
            var iframesite = prompt ('Enter in a site');
        </script>
        <iframe src="?"></iframe>
    </body>
</html>

So what would I put in the place of the "?" ? I want it to be javascript inside of the src attribute so that I can put 'https:// ' + iframesite for a src.

Thanks

PinkTurtle
  • 6,942
  • 3
  • 25
  • 44
card100
  • 76
  • 1
  • 7
  • 1
    Possible duplicate of [HTML, set iframe src as a javascript variable](http://stackoverflow.com/questions/13654868/html-set-iframe-src-as-a-javascript-variable) – Raúl Martín Mar 19 '16 at 23:06
  • Another one here http://stackoverflow.com/questions/6000987/dynamically-set-iframe-src – PinkTurtle Mar 19 '16 at 23:07

2 Answers2

1

If you want to use plain javascript you can achieve this with something like this:

var iframesite = prompt ('Enter in a site');
document.getElementsByTagName("iframe")[0].setAttribute("src", "https://" + iframesite );

Otherwise I would suggest you to have a look at jquery

Finkes
  • 496
  • 5
  • 16
0

I think adding a Iframe would work. Here is some example code:

var iframesite = prompt ('Enter in a site');
var iframe = document.createElement('iframe');
iframe.src = iframesite;
document.body.appendChild(iframe);