JS関連

2203 ワード

/**
* wrap javascript codes with a html-tag
* @author Wilson Zeng
*/
function js($script){
return '<script type="text/javascript">'."
".$script."
".'</script>'."
";
}

/**
* wrap javascript codes with a html-tag & history back
* @author Wilson Zeng
* @param $message [optional] show alert() if is given
* @param $url [optional] the next step that will jump to if is given
* @author Wilson Zeng
*/
function jsBack($message = NULL, $url = NULL, $addslashes = TRUE){
$script = '';
if($message){
$script .= 'alert("'.str_replace('"', '\"', ($addslashes ? addslashes($message) : $message)).'");';
}
$script .= $url ? 'location.href="'.$url.'";' : 'history.back();';

echo js($script);
exit(0);
}