【问题标题】:How to send form data to iframe src in same web page如何将表单数据发送到同一网页中的 iframe src
【发布时间】:2019-10-03 02:50:03
【问题描述】:

我有一个带有一个输入的表单,您可以在其中键入网站的 URL,然后 URL 应该被发送到同一网页上的 iframe,它应该 iframe 的 URL。这是我当前在 URL 输入中键入 http://example.com 时得到的代码,它给了我错误,cannot GET /my_frame%22?Url=http%3A%2F%2Fexample.com

    <html>
      <head>
        <title>Form Iframe Demo</title>
      </head>
      <body>

       <form action=my_frame" >
        <input type="text" name="Url" value="http://" />
        <input type="submit" />
      </form>
<--Iframe should receive url from the form and then Iframe it -->
        <iframe name="my_frame" src="Url" width="860px">
       </iframe>
      </body>
    </html>

尝试过使用它,但它让我陷入困境

我希望它有一个 http://example.com 的 iframe,但我收到一个错误

【问题讨论】:

标签: html forms iframe


【解决方案1】:
<html>
<head>
        <title>Form Iframe Demo</title>
      </head>
      <body>      
        <input type="text" name="Url" id="url" value="https://j-mrad.github.io/" />
        <button onClick="LoadURL();" >Load URL</button>
        <br><br>       
        <iframe id="my_frame" src="https://www.w3schools.com" width="600px" height="500px">
        </iframe>       
       <script type="text/javascript">
       function LoadURL(){
       document.getElementById("my_frame").src=document.getElementById("url").value;
       }

       </script>

      </body>
    </html>

【讨论】:

  • 您,先生,是个传奇人物,我不知道谁对您投了反对票,但这完美无瑕。
猜你喜欢
  • 1970-01-01
  • 2011-06-17
  • 2015-04-27
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-04-06
  • 2021-11-19
相关资源
最近更新 更多