知修

知而修之方为悟

  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

<?php
/**
 * 文件: alert.class.php
 * 功能: 对客户端window封装,使用php控制客户端行为
 * @author xiaog
 */
class clientWindow {
    private
        static $SCRIPT = "<script type=text/javascript>%s</script>";

 

    /**
     * 客户端转向
     */
    public static function redirect($url){
        printf(self::$SCRIPT, "location.href=\"".self::fixMsg($url)."\"");
    }

    /**
     * 向客户端发送弹出信息
     */
    public static function alert($msg) {
        printf(self::$SCRIPT, "alert(\"".self::fixMsg($msg)."\");");
    }

    /**
     * 向客户端发送弹出信息并结束页面执行
     */
    public static function alertAndExit($msg) {
        clientWindow::alert($msg);
        exit;
    }

    private static function fixMsg($msg){
        return str_replace("\"", '\"', $msg);
    }
}

posted on 2010-04-07 15:51  BoolYang  阅读(178)  评论(0编辑  收藏  举报