【问题标题】:How to display a URL from a form box using HTML and a javascript?如何使用 HTML 和 javascript 从表单框中显示 URL?
【发布时间】:2015-02-10 07:52:31
【问题描述】:

尝试使用带有 HTML 的表单框来创建可用于更改 IFRAME 的 url。这是我目前拥有的。

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

我喜欢将 IFRAME 更改为用户输入访问的网站的表单框。我知道这些信息很少,可能含糊,但我通常不会寻求帮助,也不知道还能问什么。

原始码来自:http://www.w3schools.com/jsref/tryit.asp?filename=tryjsref_url_get

【问题讨论】:

标签: javascript php jquery html iframe


【解决方案1】:

您可以通过编程方式设置iframe的URL:

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

看看这个:http://jsfiddle.net/andunai/d1zavddu/

但是,请注意许多网站,例如google.comyahoo.com 不允许将自己插入到 iframes 中。

【讨论】:

  • 正是我想要的。奇迹般有效。谢谢!
【解决方案2】:
<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>

别忘了把“x”改成url

【讨论】:

  • “强烈建议不要使用内联事件处理来处理...,而是使用事件侦听器”
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-06-29
  • 1970-01-01
  • 2018-02-17
  • 2018-04-07
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多