It's difficult to use an iframe on an online editor because of the sandbox environment but it'll behave normal under normal conditions. As a valid test, you can enter http://example.com it's whitelisted.
UPDATE
Added a PLUNKER since SO sandboxes iframes.
EDIT
I added another way to manipulate the iframe you might be interested in. Itonly involves HTML, no JS. Notice the anchor to example.com. Basically all you need to do is the following:
- Add a
name attribute to the iframe (I always have id and name the same)
- On the anchor, you change the
target attribute value to the value of the iframe's name value.
So in this demo the part inside {{{...}}} is the trick. The brackets are added for emphasis do not include them into the code to use.
<a href="http://example.com" {{{target="site"}}}>Example.com</a>
<iframe id="site" {{{name="site"}}} src="/" width="100%" height="100%" frameborder="0"></iframe>
function changeSrc(src) {
var iframe = document.getElementById('site');
iframe.src = src;
}
body {
width: 100vw;
height: 100vh;
overflow: hidden;
}
section {
height: 100%;
width: 100%;
overflow-y: auto;
}
<form id="form" onchange="changeSrc(url.value);">
<fieldset>
<legend>Enter URL</legend>
<input id="url">
</fieldset>
</form>
<a href="https://example.com" target="site">Example.com</a>
<section>
<iframe id="site" name="site" src="/" width="100%" height="100%" frameborder="0"></iframe>
</section>