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

1

2 Answers 2

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

Sign up to request clarification or add additional context in comments.

1 Comment

"The usage of inline event handling by advocation ... is heavily discouraged, instead use event listeners"
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.

1 Comment

Exactly what I wanted. Works like a charm. Thanks!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.