破阶

乘风破浪会有时,直挂云帆济沧海

PHP弹出提示框并跳转【重定向到新页面】 封装成函数

在PHP开发过程中,表单提交后跳转是常用到的技术。一般可以用js的

js例子:

echo “<script> alert(‘sucess’);window.location.href=’/product/index’; </script>”;

每次都复制一大段代码还是比较麻烦的,我们可以考虑封装成函数来调用,下面是我自己封装的页面跳转函数

页面跳转函数封装

/**
* 页面跳转方法
* @param $msg 提示说明
* @param null $path 跳转路径
* @param null $parent 例子ture返回父窗口
*/
function messageInfo($msg,$path=NULL,$parent=NULL){
if($parent === true){
$str=”<script>alert(‘”.$msg.”‘);parent.location.href='”.$path.”‘</script>”;
}else if(empty($path)){
$str=”<script>alert(‘”.$msg.”‘);history.back()</script>”;
}else{
$str=”<script>alert(‘”.$msg.”‘);location.href='”.$path.”‘</script>”;
}
echo $str;
}

使用方法:

messageInfo(‘操作成功!’,’http://www.demourl.com/product_list.php’);

 

点赞

2003年你错过了淘宝红利,2009年你错过了微博红利,2013年你错过了公众号红利,2018年你错过了抖音红利,2020年的视频号红利,你绝对不能再错过!扫码进行学习。

发表评论

邮箱地址不会被公开。 必填项已用*标注