cross-domain post iframe

谁说我不能喝 提交于 2019-12-21 05:31:21

问题


I want to POST data from my FORM to an IFRAME which is found on another domain. Is there any easy way to do this?

<iframe name="iframe" width="100" height="100" src="www.otherdomain.com" />

<form action="www.mydomain.com" method="post" target="iframe">
<input type="text" name="text1" value="123" />
<input type="text" name="text2" value="456" />
<input type="submit" value="submit"/>
</form>

回答1:


I think your example should work. I've set two virtual hosts pastefrom.com pasteto.com on my localhost.

http://pastefrom.com/index.html:

<!DOCTYPE HTML>
<html>
<head>
    <meta http-equiv="Content-type" content="text/html; charset=utf-8" />
    <title>test</title>
</head>
<body>
<iframe name="iframe" id="iframe" src="http://pasteto.com/index.php" width="500" height="500"></iframe>

<form action="http://pasteto.com/index.php" method="post" target="iframe">
    <input type="text" name="search" value="google" />
    <input type="submit" value="submit"/>
</form>

</body>
</html>

http://pasteto.com/index.php:

<pre><?php var_dump($_POST);?></pre>

And on submit it shows post data on pasteto.com

array(1) {
  ["search"]=>
  string(6) "google"
}


来源:https://stackoverflow.com/questions/8446210/cross-domain-post-iframe

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!