[英]refresh url in iframe after a submit button of another form is clicked &formatting url contents inside iframe
如何通過JavaScript重新加載由於onload調用而已經“呈現”的iframe。 我有一個頁面可以在其中添加新用戶(輸入名稱后單擊提交按鈕)。 該頁面還會顯示iframe中的所有可用用戶(在加載期間,iframe會“預加載”用戶)。 每當我添加新用戶並單擊提交時,iframe(列表)也應自動獲取更新的列表。
我也想知道如何以隱藏形式設置URL“ get”結果的格式。 復制到iframe中的網址能否在目標位置進行修改?
我怎樣才能做到這一點? 請幫忙!
這是我到目前為止的內容:
<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>
答案肯定是正如其他人所評論的:
document.getElementById("myFrame").src = "http://www.google.com/"
有幾種原因可能導致此操作無效。 最有可能是違反了JS“相同來源”政策。 嘗試將src設置為相對網址,例如"getusers/"
並注意控制台錯誤。
嘗試OnButton2()
調用OnButton2()
,看看是否可以縮小問題的范圍。
此外,這聽起來很像您在嘗試將數據加載到DOM中而不重新加載頁面。 您是否嘗試過使用AJAX ? 一旦掌握了使用它的功能,它就非常簡單而強大,它使您可以提交表格並以所需的任何格式顯示結果,而無需使用iframe或重新加載頁面。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.