简体   繁体   English

如何在父网页上捕获iframe POST数据

[英]How to catch iframe POST data on the parent webpage

I have a webpage with an iframe : 我有一个带有iframe的网页:

<iframe id="foo" src="foo.html"></iframe>

This iframe hosts an hidden form (foo.html) which is submitted to an external page on another domain ( http://example.com/foobar ) : 此iframe托管一个隐藏表单(foo.html),该表单已提交到另一个域( http://example.com/foobar )上的外部页面:

<form name="foobar" action="http://example.com/foobar" method="POST">
  <input type="hidden" name="returnURL" value="bar.html">
</form>
<script type="text/javascript">
  document.foobar.submit();
</script>

The external webpage consists of a series of forms. 外部网页由一系列表格组成。 On its final form, the validation submits POST data to the URL set in returnURL . 验证的最终形式是将POST数据提交到returnURL设置的URL。

From the user point of view, what happens currently is that the browser is redirected to returnURL . 从用户的角度来看,当前发生的是将浏览器重定向到returnURL This is not what I want. 这不是我想要的。

What I need is to treat the POST data within the original webpage, without it being refreshed. 我需要的是在原始网页内处理POST数据,而无需刷新它们。

I can think of a few options : 我可以想到一些选择:

  • triggering on the iframe POST exit and catch POST data ; 在iframe POST出口上触发并捕获POST数据;
  • setting returnURL to the original webpage and handle the POST data without reloading the page ; returnURL设置为原始网页并处理POST数据而无需重新加载页面;
  • setting returnURL to another webpage and update the current page when it receives the POST data. returnURL设置为另一个网页,并在接收到POST数据时更新当前页面。

Unfortunately I don't seem able to implement any of these. 不幸的是,我似乎无法实现所有这些。 What would be the best option, and where should I start ? 最佳选择是什么,我应该从哪里开始?

Use of jQuery is allowed. 允许使用jQuery。

只要您位于不同的域中,javascript中的安全限制将阻止您在两个框架之间进行通信。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM