【问题标题】:How to redirect onclick while using iframe如何在使用 iframe 时重定向 onclick
【发布时间】:2017-06-07 09:03:44
【问题描述】:

在操作完成之前,我必须使用 iframe 来阻止页面重新加载。但是,我需要在操作发生后刷新它。我为此尝试了两种方法,刷新页面并重定向到同一页面。

PHP:

if(isset($_POST['btn_name']) {
   //Action
   location.reload(); 
  //I also tried 
    header("Location: index.php");
} 

HTML:

<iframe width="0" height="0" border="0px solid white" style="display:none" name="iframe1" id="iframe1"></iframe>

        <form action="index.php" method="post" target="iframe1">
         <input type="submit" href="" style="margin-top:5px" name="btn_name" class="btn btn-success" value="Enter">
            </form>

感谢您的帮助。感谢所有输入。

【问题讨论】:

    标签: php html iframe


    【解决方案1】:

    $_POST['btn'] 不发布任何内容,因为它是一个类。

    改用$_POST['installer4_btn']

    【讨论】:

    • 最好是'header('Location: index.php');`
    【解决方案2】:

    尝试在你的 iframe 所在的页面中添加这个(这是使用 jquery)

    $('#iframe1').load(function() { if (this.contentWindow.location.href === 'http://location_redirected_in_php') { window.location.href = '/redirect_location'; } });

    【讨论】:

    • 这实际上会在 iframe 重新加载时添加一个侦听器,因此如果您在成功提交或在 php 中处理后重新加载页面,您需要做的就是获取它将结束的位置并检查它如果 iframe 具有该 url,请重新加载您的父页面。
    猜你喜欢
    • 1970-01-01
    • 2020-09-20
    • 1970-01-01
    • 2014-05-21
    • 1970-01-01
    • 1970-01-01
    • 2012-07-14
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多