跨域发布iframe [英] cross-domain post iframe

查看:210
本文介绍了跨域发布iframe的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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>


推荐答案

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

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>

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

And on submit it shows post data on pasteto.com

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

这篇关于跨域发布iframe的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆