Home >Backend Development >PHP Tutorial >How to implement universal alert function in PHP, php universal alert function_PHP tutorial

How to implement universal alert function in PHP, php universal alert function_PHP tutorial

WBOY
WBOYOriginal
2016-07-13 10:04:08913browse

PHP实现通用alert函数的方法,php通用alert函数

本文实例讲述了PHP实现通用alert函数的方法。分享给大家供大家参考。具体如下:

函数:通用提示
参数:提示訊息,類型或網址,窗口名或函數名,延时毫秒
Alert("","function","close2",300);

代码如下:

function Alert($Str,$Typ="back",$TopWindow="",$Tim=100){
  echo "<script>".chr(10);
  if(!empty($Str)){
    echo "alert(\"Warning:\\n\\n{$Str}\\n\\n\");".chr(10);
  }
  echo "function _r_r_(){";
  $WinName=(!empty($TopWindow))&#63;"top":"self";
  switch (StrToLower($Typ)){
  case "#":
    break;
  case "back":
    echo $WinName.".history.go(-1);".chr(10);
    break;
  case "reload":
    echo $WinName.".window.location.reload();".chr(10);
    break;
  case "close":
    echo "window.opener=null;window.close();".chr(10);
    break;
  case "function":
    echo "var _T=new function('return {$TopWindow}')();_T();".chr(10);
    break;
    //Die();
  Default:
    if($Typ!=""){
      //echo "window.{$WinName}.location.href='{$Typ}';";
      echo "window.{$WinName}.location=('{$Typ}');";
    }
  }
  echo "}".chr(10);
  //為防止Firefox不執行setTimeout
  echo "if(setTimeout(\"_r_r_()\",".$Tim.")==2){_r_r_();}";
  if($Tim==100){
    echo "_r_r_();".chr(10);
  }else{
    echo "setTimeout(\"_r_r_()\",".$Tim.");".chr(10);
  }
  echo "</script>".chr(10);
  Exit();
}

希望本文所述对大家的php程序设计有所帮助。

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/966544.htmlTechArticlePHP实现通用alert函数的方法,php通用alert函数 本文实例讲述了PHP实现通用alert函数的方法。分享给大家供大家参考。具体如下: 函数:通用提...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn