2011-07-18 133 views
18

我必须使用POST方法将一些参数发送到IFRAME。 我已经在这里读到Setting the HTTP request type of an <iframe>这是不可能的。我想在Javascript中的解决方案,但我不能实现它,所以我不能测试它是否是这个问题的有效解决方案。 我想问问是否有人有同样的问题,如果有可能解决,并在积极情况下如何?如何使用HTTP POST请求将参数发送到Iframe

+0

见http://stackoverflow.com/questions/168455/how-do-you-post-to-an-iframe –

回答

29
<form ... target="hidden_iframe"> 
... 
</form> 

<iframe name="hidden_iframe" ...></iframe> 
+0

只是使形式隐形和iframe太..然后做一个表格提交通过js – walialu

16

如何使用窗体的target属性指向iFrame?

<form target="myIframe" action="http://localhost/post.php" method="post"> 
    <input type="hidden" value="someval" /> 
    <input type="submit"> 
</form> 

<iFrame src="" name="myIframe"></iFrame> 
+0

正是我回答16分钟前-.- – walialu

+1

刚刚注意到你的。向上投票你的。 – KishoreK

+0

这样可以解决除Internet Explorer 7以外的所有浏览器的问题。您有任何建议吗? – jRicca

8

只给一个具体的工作示例

<form id="loginForm" target="myFrame" action="https://localhost/j_spring_security_check" method="POST"> 
<input type="text" name="j_username" value="login" /> 
<input type="text" name="j_password" value="password" /> 
<input type="submit"> 
</form> 

<iframe name="myFrame" src="#"> 
    Your browser does not support inline frames. 
</iframe> 

// Hide the form and do the submit 
<script> 
$(document).ready(function(){ 
var loginform= document.getElementById("loginForm"); 
loginform.style.display = "none"; 
loginform.submit(); 
}); 
</script>