将 POST 页面加载到 <iframe> 中,而无需使用 javascript

Loading a POST page into <iframe> without having to use javascript

本文关键字:javascript iframe POST 加载      更新时间:2023-09-26

有一个问题解决了"使用JavaScript发布到iframe"。

我的场景:

我不允许使用 JavaScript 或其任何库。我唯一能使用的就是PHP和HTML。

  • 页1.php:

       <form action="Page2.php">
            <input type="....  >
             .
             .
             .
       </form>
    
  • 页2.php:

       <iframe src="http://externalsite.com/post-to-this-address-thru-iframe">
       </iframe>
    

当使用 JavaScript 时,这总是可能的。使用 PHP 的 post 函数(如 curl)也是行不通的。真的有光源适合我吗?

根据我的评论。

  1. 将名称属性添加到您的 iframe。
  2. 将表单的目标设置为 iframe 的名称。

http://jsfiddle.net/gRoberts/GZPqM/

注意 - 似乎JSFiddle不喜欢你在他们的网站上发帖,因此你会得到一些奇怪的JSON输出。

如果您可以控制 Page2.phphttp://externalsite.com/,则可以将从表单发布的所有数据连接为 iframe src 字段中的 GET 请求:

<iframe src="http://externalsite.com/post-to-this-address-thru-iframe/?param1=val1&param2=val2">
</iframe>