2

Trying to use a form box with HTML to create a url that can be used to change an IFRAME. This is what I currently have.

<input type="url" id="URL" value="">
<button onclick="webFunct()">Go!</button>
<br><a href= id="ViewURL" target="WebViewer></p>

<script>
function webFunct() {
    var x = document.getElementById("URL").value;
    document.getElementById("ViewURL").innerHTML = x;
}
</script>

<iframe width="100%" height="640px" name="WebViewer">
</iframe>

I like the form box to change the IFRAME to the website that was entered by the user to visit. I know this information is minimal and possibly vague but I normally don't ask for help and I don't know what else to ask.

Original code from: http://www.w3schools.com/jsref/tryit.asp?filename=tryjsref_url_get

Nerokin
  • 23
  • 3

2 Answers2

4
<input type="url" id="URL" value="">
<button onclick="webFunct()">Go!</button>

<script>
function webFunct() {

    document.getElementById("frame").src = x;
}
</script>

<iframe width="100%" id="frame" height="640px" name="WebViewer">
</iframe>

Dont forget to change "x" to an url

Alexis Peters
  • 1,583
  • 1
  • 10
  • 17
  • *"The usage of inline event handling by advocation ... is heavily discouraged, instead use event listeners"* – arielnmz Dec 11 '14 at 18:14
3

You can set URL of iframe programmatically:

document.getElementById('web-view').src = url;

Check this out: http://jsfiddle.net/andunai/d1zavddu/

However, please note that many websites, e.g. google.com and yahoo.com do not permit getting themselves inserted into iframes.

Funk Forty Niner
  • 74,450
  • 15
  • 68
  • 141
Andrew Dunai
  • 3,061
  • 19
  • 27