douding7189 2014-12-11 18:04
浏览 23
已采纳

如何使用HTML和JavaScript从表单框中显示URL?

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

  • 写回答

2条回答 默认 最新

  • doufu6423 2014-12-11 18:11
    关注

    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条)

报告相同问题?