Home >Backend Development >PHP Tutorial >How to implement a universal alert function in PHP_PHP tutorial

How to implement a universal alert function in PHP_PHP tutorial

WBOY
WBOYOriginal
2016-07-13 10:03:501050browse

How to implement the universal alert function in PHP

This article mainly introduces the method of implementing the universal alert function in PHP, and analyzes the techniques of PHP custom alert function to implement prompt information. It is of great practical value, friends in need can refer to it

The example in this article describes how to implement the universal alert function in PHP. Share it with everyone for your reference. The details are as follows:

Function: General Tips
Parameters: prompt message, type or URL, window name or function name, delay milliseconds
Alert("","function","close2",300);

The code is as follows:

?

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

function Alert($Str,$Typ="back",$TopWindow="",$Tim=100){

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

Exit();

}

1 2

3

4 5

67 8 9 10 11 12
13
14
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
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))?"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); //To prevent Firefox from not executing 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(); }
I hope this article will be helpful to everyone’s PHP programming design. http://www.bkjia.com/PHPjc/966932.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/966932.htmlTechArticleHow to implement the universal alert function in PHP. This article mainly introduces the method of implementing the universal alert function in PHP and analyzes the examples. The skill of php custom alert function to realize prompt information is very practical...
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