简体   繁体   English

我如何通过php脚本关闭对话框

[英]how i close dialog box through php script

    if(isset($_POST[submit])){  

       $exclude=array('submit');

       $sql ="insert into products set ";
       foreach($_POST as $k=>$v){
          if(!in_array($k,$exclude)){
              $sql_array[]= mysql_real_escape_string($k)." = '".mysql_real_escape_string($v)."' ";
          }
       }

       $sql .= implode(",",$sql_array);
       $q=mysql_query($sql) or die(mysql_error());
       if($q) {
          echo 'Inserted';
       }

    }

This coding is on iframe inside dialog box. 该编码位于对话框内的iframe中。 I want to close dialog box after submitting form. 我要在提交表单后关闭对话框。 How can i do this ? 我怎样才能做到这一点 ?

step 1: 第1步:

add a js function in parent window which close the iframe 在父窗口中添加一个js函数,以关闭iframe

function close_iframe()
{
   $('#iframe_id').remove();
}

step 2: 第2步:

call this js function from iframe when successfully inserted like 成功插入后从iframe调用此js函数,例如

if($q){
     echo 'Inserted';
?>
         <script>
               parent.close_iframe();
         </script>
<?php
     }

you have to do this by using javascript as php cant work on client side. 您必须通过使用javascript来做到这一点,因为php无法在客户端运行。 use this after submitting - 提交后使用它-

echo "<script> window.close(); </script>";

this might work. 这可能有效。

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

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