Home  >  Article  >  Backend Development  >  How to write a prompt box similar to alert() in js in PHP

How to write a prompt box similar to alert() in js in PHP

墨辰丷
墨辰丷Original
2018-06-12 14:14:303512browse

This article mainly introduces PHP to implement a prompt box function similar to the alert() in js. It is very practical. I recommend it to everyone. Friends who need it can refer to it. I hope you will like it.

Mainly used for adding judgment prompts, jumps, returns, and refreshes.

The code is as follows:

/**
 * JS提示跳转
 * @param  $tip  弹窗口提示信息(为空没有提示)
 * @param  $type 设置类型 close = 关闭 ,back=返回 ,refresh=提示重载,jump提示并跳转url
 * @param  $url  跳转url
 */
function alert($tip = "", $type = "", $url = "") {
    $js = "<script>";
    if ($tip)
        $js .= "alert(&#39;" . $tip . "&#39;);";
    switch ($type) {
        case "close" : //关闭页面
            $js .= "window.close();";
            break;
        case "back" : //返回
            $js .= "history.back(-1);";
            break;
        case "refresh" : //刷新
            $js .= "parent.location.reload();";
            break;
        case "top" : //框架退出
            if ($url)
                $js .= "top.location.href=&#39;" . $url . "&#39;;";
            break;
        case "jump" : //跳转
            if ($url)
                $js .= "window.location.href=&#39;" . $url . "&#39;;";
            break;
        default :
            break;
    }
    $js .= "</script>";
    echo $js;
    if ($type) {
        exit();
    }
}

Summary: The above is the entire content of this article, I hope it will be helpful to everyone's study.

Related recommendations:

PHP implements refresh-free login and exit based on Ajax

php operation color value conversion color to Inverse color

#Briefly describe the method of intercepting Chinese characters in PHP to prevent garbled characters

The above is the detailed content of How to write a prompt box similar to alert() in js in PHP. For more information, please follow other related articles on the PHP Chinese website!

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