二 JS類 封裝常用javascript以便PHP快速調用

來源:互聯網
上載者:User
js|封裝 <?php
//
// +----------------------------------------------------------------------+
// | JS        javascript 類                                              |
// +----------------------------------------------------------------------+
// | Copyright (c) 2001 NetFish Software                                  |
// |                                                                      |
// | Author: whxbb(whxbb@21cn.com)                                        |
// +----------------------------------------------------------------------+
//
// $Id: js.class.php,v 0.1 2001/8/5 18:48:33 yf Exp $
//

// 禁止直接存取該頁面
if (basename($HTTP_SERVER_VARS['PHP_SELF']) == "js.class.php") {
    header("HTTP/1.0 404 Not Found");
}

/**
* Purpose
* 封裝了一些常用的Javascript代碼,以便在PHP中快速調用
* @author  : whxbb(whxbb@21cn.com)
* @version : 0.1
* @date    :  2001/8/5
*/
class JS
{
    function JS(){}
    
    /**
     * 返回上頁
     * @param $step 返回的層數 預設為1
     */
    function Back($step = -1)
    {
        $msg = "history.go(".$step.");";
        JS::_Write($msg);
        JS::FreeResource();
        exit;
    }

    /**
     * 彈出警告的視窗
     * @param $msg 警告資訊
     */
    function Alert($msg)
    {
        $msg = "alert(\"".$msg."\");";
        JS::_Write($msg);
    }
    /**
     * 寫js
     * @param $msg
     */
    function _Write($msg)
    {
        echo "<script language=\"javascript\">\n";
        echo $msg;
        echo "\n</script>";
    }

    /**
     * 重新整理當前頁
     */
    function Reload()
    {
        $msg = "location.reload();";
        JS::FreeResource();
        JS::_Write($msg);
        exit;
    }
    /**
     * 重新整理彈出父頁
     */
    function ReloadOpener()
    {
        $msg = "if (opener)    opener.location.reload();";
        JS::_Write($msg);
    }

    /**
     * 跳轉到url
     * @param $url 目標頁
     */
    function Goto($url)
    {
        $msg = "location.href = '$url';";
        JS::FreeResource();
        JS::_Write($msg);
        exit;
    }
    /**
     * 關閉視窗
     */
     function Close()
     {
         $msg = "window.close()";
        JS::FreeResource();
        JS::_Write($msg);
        exit;
        
     }
    /**
     * 提交表單
     * @param $frm 表單名
     */
    function Submit($frm)
    {
        $msg = $frm.".submit();";
        JS::_Write($msg);
    }
    /**
     * 關閉資料庫連接
     */
    function FreeResource()
    {
        // 資料庫連接標誌
        global $conn;
        if (is_resource($conn))
            @mysql_close($conn);
    }
}
?>

相關文章

Beyond APAC's No.1 Cloud

19.6% IaaS Market Share in Asia Pacific - Gartner IT Service report, 2018

Learn more >

Apsara Conference 2019

The Rise of Data Intelligence, September 25th - 27th, Hangzhou, China

Learn more >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。