php調用javascript

來源:互聯網
上載者:User

封裝常用的JS參數方便PHP調用: <?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">";
echo $msg;
echo "</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);
}
}
?>

聯繫我們

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

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

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.