그누보드4 alert 함수를 튜닝해서 sweetalert로 교체하는 작업 중인데
본문
그누보드4 alert 함수를 튜닝해서 sweetalert로 교체하는 작업 중인데
function alert($msg='', $url='')
{
global $g4;
if (!$msg) $msg = '올바른 방법으로 이용해 주십시오.';
//header("Content-Type: text/html; charset=$g4[charset]");
echo "<meta http-equiv=\"content-type\" content=\"text/html; charset=$g4[charset]\">";
//echo "<script language='javascript'>alert('$msg');";
if (!$url)
echo "<script language='javascript'>swal( {title:'$msg'},function(){ history.go(-1); } );</script>";
if ($url)
// 4.06.00 : 불여우의 경우 아래의 코드를 제대로 인식하지 못함
//echo "<meta http-equiv='refresh' content='0;url=$url'>";
//goto_url($url);
echo "<script language='javascript'>swal( {title:'$msg'},function(){ location.replace('$url'); } );</script>";
exit;
}
head.sub.php 쪽에 <script src="/assets/plugins/sweetalert.min.js"></script> 추가하고 사용하려고 하니
html 코드 없이 head, tail 없는 php만 있는곳에서는 오류가 나버리더군요.
그래서
function alert($msg='', $url='')
{
global $g4;
if (!$msg) $msg = '올바른 방법으로 이용해 주십시오.';
//header("Content-Type: text/html; charset=$g4[charset]");
echo "<meta http-equiv=\"content-type\" content=\"text/html; charset=$g4[charset]\">";
echo '<body>';
echo '<script src="/assets/plugins/sweetalert.min.js"></script>';
echo '<link rel="stylesheet" href="/assets/plugins/sweetalert.css">';
//echo "<script language='javascript'>alert('$msg');";
if (!$url)
echo "<script language='javascript'>swal( {title:'$msg'},function(){ history.go(-1); } );</script>";
if ($url)
// 4.06.00 : 불여우의 경우 아래의 코드를 제대로 인식하지 못함
//echo "<meta http-equiv='refresh' content='0;url=$url'>";
//goto_url($url);
echo "<script language='javascript'>swal( {title:'$msg'},function(){ location.replace('$url'); } );</script>";
exit;
}
그래서 임시로 나마 저렇게 코드를 추가 시켜서 실행시켰는데 더 좋은 방법이 있을까요?