简体   繁体   English

如何使用Javascript或jQuery动态更新iframe

[英]How do I dynamically update an iframe using Javascript or jQuery

I am developing a page in with a text box, a submit button, and an iframe. 我正在开发一个带有文本框,提交按钮和iframe的页面。

The URL should be put in the text box. 该URL应该放在文本框中。 Upon hitting the button, the result should appear in the iframe. 按下按钮后,结果应显示在iframe中。

How do I do this? 我该怎么做呢?

You should not need JavaScript at all. 您根本不需要JavaScript。 Set the target attribute of your form to the name of the frame, and it will load there. 将表单的目标属性设置为框架的名称,它将在此处加载。

See also the duplicate How do you post to an iframe? 另请参阅副本。 您如何发布到iframe? .

Here is a quick solution for now using js 这是现在使用js的快速解决方案

 <form target="#" name="iframeform" action="post">

     <input type="text" value="http://" name="framefood" id="framefood" /><br />
     <button id="feedframe" onclick="completeFrame(); return false;">Send</button><br /><br />
     <iframe id="feedme" width="600" height="400"></iframe>
 </form>
 <script>

     var completeFrame = function(e){
         var feidlId = document.getElementById("framefood");
         var frameSrc    =   feidlId.value;
         var frameId = document.getElementById("feedme");
         frameId.src =   frameSrc;
     }

 </script>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM