简体   繁体   English

单击其他表单的提交按钮后刷新iframe中的url,并格式化iframe中的url内容

[英]refresh url in iframe after a submit button of another form is clicked &formatting url contents inside iframe

How can I reload an iframe which is already "rendered" due onload call through a javascript. 如何通过JavaScript重新加载由于onload调用而已经“呈现”的iframe。 I have a page where I can add new users (by clicking submit button after entering name). 我有一个页面可以在其中添加新用户(输入名称后单击提交按钮)。 The page also displays all available users in an iframe(during onload, the iframe is "preloaded" with users). 该页面还会显示iframe中的所有可用用户(在加载期间,iframe会“预加载”用户)。 Everytime I add a new user and click on submit, the iframe(list) should also fetch the updated list automatically. 每当我添加新用户并单击提交时,iframe(列表)也应自动获取更新的列表。

Also I am wondering how I can format the URL "get" results in the hidden form. 我也想知道如何以隐藏形式设置URL“ get”结果的格式。 Can a URL copied into an iframe be modified at the destination? 复制到iframe中的网址能否在目标位置进行修改?

How can I do this? 我怎样才能做到这一点? Please help! 请帮忙!

This is what I have so far: 这是我到目前为止的内容:

    <html>
    <head><title>welcome page</title>
    </head>
    <body onLoad ="subMe()">
    <script>
    function subMe(){
            document.getElementsByTagName('form')[1].submit();
    }
    function OnButton2()
{

     document.getElementById("myframe").src ='http://localhost:8000/getusers/' ;
}
    </script>
    <div align="center">
    <h1>Home</h1>

    <form name ="Form0" action= "/cgi-bin/myuser.cgi" method ="get" target="uframe" onsubmit="return OnButton2();">
    Enter Name:<input type="text" id ="name" name="name">
    <input type="submit" value="Create new User">
    </form>
    <iframe id="uframe" name="uframe"></iframe>
    <br>
    <div style="display: hidden;">
        <form action="http://localhost:8000/getusers/" method="get" target="myframe">
        </form>
    </div>
    <iframe id="myframe" name="myframe"></iframe>
    </div>
    </body>

The answer is definitely as others have commented: 答案肯定是正如其他人所评论的:

document.getElementById("myFrame").src = "http://www.google.com/"

There are a few reasons why this may not work. 有几种原因可能导致此操作无效。 The most likely is that JS "same origin" policy is being violated. 最有可能是违反了JS“相同来源”政策。 Try setting the src to a relative url like "getusers/" and watch for console errors. 尝试将src设置为相对网址,例如"getusers/"并注意控制台错误。

Try also calling OnButton2() on its own and see if you can narrow down the problem. 尝试OnButton2()调用OnButton2() ,看看是否可以缩小问题的范围。

Additionally, It sounds a lot like you are trying to load data into the DOM without reloading the page. 此外,这听起来很像您在尝试将数据加载到DOM中而不重新加载页面。 Have you tried using AJAX ? 您是否尝试过使用AJAX it's very simple and powerful once you get the hang of using it and will allow you to submit a form and display results in any format you wish, without using iframes or reloading the page. 一旦掌握了使用它的功能,它就非常简单而强大,它使您可以提交表格并以所需的任何格式显示结果,而无需使用iframe或重新加载页面。

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

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