【问题标题】:Iframe Submission then Redirectiframe 提交然后重定向
【发布时间】:2012-09-19 19:32:25
【问题描述】:

如何让 iframe 保持其默认提交但在将用户重定向到另一个页面之后。我听说我需要在服务器端做这个重定向,但不知道这是什么意思。

以下是我尝试过的,但它取消了默认的 iframe 提交并只是重定向。

function convert() {
            document.location = '/sidingsuccess';
}

onSubmit="convert();"

关于 iframe 代码

【问题讨论】:

  • 您需要更好地解释一下.. 当人们单击 iframe 中的表单时,您希望将页面“/sidingsuccess”加载到哪里?在同一个 iframe 中?还是浏览器中的整页?

标签: php javascript iframe


【解决方案1】:

在服务器上,您可以在提交完成后,使用header 函数将页面重定向到另一个页面(例如example.php),方法是:

header('Location: example.php');

这就是你要找的吗?

【讨论】:

  • 是的,所以我只需要放 onsubmit="header ();"在 iframe 上?
  • header 是一个 php 函数,你必须在服务器上调用它。你不能在客户端调用它。只需将其添加到处理您提交的 php 页面的末尾即可。
  • 我没有处理提交的页面,iframe 将提交发送给附属公司。我希望重定向跟踪转化,但无法控制 iframe 代码
【解决方案2】:

提交表单到隐藏的 iframe。

iframe HTML:

<g:form controller="..." action="submit" method="POST" target="hidden-frame">
...
</g:form>

<iframe id="hidden-frame" style="display: none" onload="onSubmitCompleted"></iframe>

<script>
    function onSubmitCompleted() {
        window.top.location.href = <redirect url>
    }
</script>

控制器:

/*process submission */

render("<html><head><script>window.parent.onSubmitCompleted();</script></head><body></body></html>");

【讨论】:

  • 所以我托管的 iframe 表单应该按照正常方式提交,然后重定向而不搞砸提交?
  • 这就是整个想法。隐藏的 iframe 可帮助您在提交后留在页面上
  • 好的,所以
    代码应该放在我的 iframe 中,然后你的
  • 我不熟悉php,但必须有代码/方法处理您的提交。该方法应该响应渲染方法中使用的字符串。如果您将字符串更改为 ...onSubmitCompleted(eval(${result}))... 我使用 json 作为结果,您甚至可以将结果传递给 onSubmitCompleted js fn。如果您传递 true/false,则可以省略 eval。
【解决方案3】:

替换您的以下行:

document.location = '/sidingsuccess';

对于这个:

window.top.location.href = '/sidingsuccess';

应该这样做。

【讨论】:

    猜你喜欢
    • 2013-08-06
    • 2012-03-29
    • 2021-10-02
    • 2012-08-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多