跨域发布iframe

时间:2011-12-09 13:33:10

标签: post iframe dns

我想将我的FORM中的数据发布到另一个域上的IFRAME。有没有简单的方法呢?

<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 个答案:

答案 0 :(得分:5)

我认为你的例子应该有效。我已经设置了两个虚拟主机pastefrom.com pasteto.com  在我的本地主机上。

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>

在提交时,它会在pasteto.com上显示发布数据

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