一、效果展示
1、安裝前效果
2、安裝后效果
二、安裝說明
1、安裝測試版本:DedeCMS-V5.7.117-UTF8;
2、必須在修改代碼之前請做好文件備份,以免誤操無法恢復;
3、為了兼容其他版本,請在安裝時,最好將替換前的代碼和替換后的代碼對比一下,除模版代碼之外是否有其他改動;
4、安裝后效果作用于前臺和后臺
三、安裝教程
第一步、打開修改文件
找到并打開文件【/include/common.func.php】
第二步、找到要替換的代碼
???開始代碼(大約在288行)
function ShowMsg($msg, $gourl, $onlymsg=0, $limittime=0)
{
中間代碼省略部分……
? ?echo $msg;
}
???結束代碼(大約在351行)
????開始???
????結束???
第三步:替換并修改代碼
將下面美化的代碼替換上面這段代碼:
function ShowMsg($msg, $gourl, $onlymsg=0, $limittime=0){if(empty($GLOBALS['cfg_plus_dir'])) $GLOBALS['cfg_plus_dir'] = '..';$htmlhead = "<html>\r\n<head>\r\n<title>提示信息</title>\r\n<meta http-equiv=\"Content-Type\" content=\"text/html; charset=gb2312\" />\r\n<meta name=\"viewport\" content=\"width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no\">\r\n<meta name=\"renderer\" content=\"webkit\">\r\n<meta http-equiv=\"Cache-Control\" content=\"no-siteapp\" />";$htmlhead .= "<base target='_self'/>\r\n<style>div{line-height:160%;}</style></head>\r\n<body leftmargin='0' topmargin='0' bgcolor='#FFFFFF'>".(isset($GLOBALS['ucsynlogin']) ? $GLOBALS['ucsynlogin'] : '')."\r\n<center>\r\n<script>\r\n";$htmlfoot = "</script>\r\n</center>\r\n</body>\r\n</html>\r\n";$litime = ($limittime==0 ? 1000 : $limittime);$func = '';if($gourl=='-1'){if($limittime==0) $litime = 5000;$gourl = "javascript:history.go(-1);";}if($gourl=='' || $onlymsg==1){$msg = "<script>alert(\"".str_replace("\"","“",$msg)."\");</script>";}else{//當網址為:close::objname 時, 關閉父框架的id=objname元素if(preg_match('/close::/',$gourl)){$tgobj = trim(preg_replace('/close::/', '', $gourl));$gourl = 'javascript:;';$func .= "window.parent.document.getElementById('{$tgobj}').style.display='none';\r\n";}$func .= " var pgo=0;function JumpUrl(){if(pgo==0){ location='$gourl'; pgo=1; }}\r\n";$rmsg = $func;$rmsg .= "document.write(\"<style>body{background:#F6F6F6}.tips-box{margin-top:50px;padding:0;width:450px;border:10px solid #E8E8E8;background:#fff;color:#444;font-family:微軟雅黑}.tips .title{margin:0 20px;padding:15px 0;border-bottom:1px dotted #DDD;text-align:left;font-size:15px}.tips .title p{padding-left:10px;height:18px;border-left:2px solid #009688;font-weight:600;line-height:18px;margin: 0;}.tips .content{position:relative;padding:30px;height:120px;background:#fff;color:#666;font-size:15px}.tips .content p.tip{color:#999;font-size:1px}.tips .content a.go{display:block;margin:15px auto 0;padding:6px 10px;width:80px;border:1px solid #019688;border-radius:3px;color:#1AA094;text-decoration:blink;font-size:13px}.tips .content a:hover{background:#1AA094;color:#fff}</style>\");\r\n;";$rmsg .= "document.write(\"<div class='tips tips-box'>";$rmsg .= "<div class='title'><p>提示信息</p></div>\");\r\n";$rmsg .= "document.write(\"<div class='content'>\");\r\n";$rmsg .= "document.write(\"".str_replace("\"","“",$msg)."\");\r\n";$rmsg .= "document.write(\"";if($onlymsg==0){if( $gourl != 'javascript:;' && $gourl != ''){$rmsg .= "<a href='{$gourl}' class='go'>點擊跳轉</a>";$rmsg .= "<br/></div>\");\r\n";$rmsg .= "setTimeout('JumpUrl()',$litime);";}else{$rmsg .= "<br/></div>\");\r\n";}}else{$rmsg .= "<br/><br/></div>\");\r\n";}$msg = $htmlhead.$rmsg.$htmlfoot;}echo $msg;}
第四步、保存并上傳文件
將替換好的【/include/common.func.php】文件,保存并上傳到你的站點;
第五步、測試效果
1、前臺測試效果:進入搜索頁,在3秒內連續點擊兩次搜索,會有提示彈出;
2、后臺測試效果:直接登錄后臺管理員,會有登錄成功提示;
以上美化已經完成。
四、僅優化 "DedeCMS 提示信息!”標題
1、如果你不想美化提示界面,只想修改“DedeCMS提示信息”標題
2、還是這個文件,找【DedeCMS 提示信息】關鍵詞,有2處要修改
3、直接修改成你自己定義的標題名稱即可;
五、其他ShowMsg函數說明
關于Dede Cms系統提示方式修改以及ShowMsg函數說明
DedeCMS的所有提示信息都是用ShowMsg方法進行處理的,我們先來了解一下ShowMsg函數
源碼格式:
/*** 短消息函數,可以在某個動作處理后友好的提示信息** @param string $msg 消息提示信息* @param string $gourl 跳轉地址* @param int $onlymsg 僅顯示信息* @param int $limittime 限制時間* @return void*/
function ShowMsg($msg, $gourl, $onlymsg=0, $limittime=0)
格式:ShowMsg($msg, $gourl, $onlymsg=0, $limittime=0)
$msg:參數是要返回的信息,也就是提示的問題;
$gourl:參數是提示完成后要返回的頁面,參數有:
① -1 代表返回上一頁;
②?直接寫頁面名稱,如【index.php】?表示返回指定的index.php頁面;
ShowMsg(“成功登錄,5秒鐘后轉向系統主頁…”,“index.php”,0,2000);
javascript:window.opener=null;window.open(’’,’_self’);window.close(); 關閉當前跳轉的提示窗口;
$limittime:參數是提示停留的秒數,以毫秒為單位;1000就是1秒。
$onlymsg:參數是提示的顯示方式,具體參數有:
① $onlymsg=0 為0,則以跳轉到新頁面顯示;
②?$onlymsg<>0 不為0,則以彈出對話框的形式進行顯示
如果gourl為空,或者onlymsg==1,跳轉的頁面是空白;
下面舉例說明兩種修改方法;
DedeCMS的提示信息默認的是跳轉,好處是防止有些瀏覽器禁止了彈出窗口,但用戶體驗稍差,可以修改提示信息為彈窗更友好,制作做兩種修改方法:
方法一:舉個表單提交的例子:
① 表單字段為空,彈出對話框提示信息,不提交表單,返回;
② 表單信息完整無誤,更改點擊提交后的跳轉為彈出“成功提交”對話框信息,關閉當前窗口并刷新;
修改如下:
1、找到
$msg = "<script>alert(\"".str_replace("\"","“",$msg)."\");</script>";
修改為:
$msg = "<script>history.go(-1);location.reload()</script>";
?讓$gourl值為1時,就能實現返回上級(歷史)頁面并刷新,但并不提示任何信息。
這樣做的好處是:htm頁面內編寫JS判斷字段數據是否規范,不滿足條件不能提交,不必提示信息跳轉。
結合點擊或回車事件,在所需要修改的模板之前增加代碼
對應的提交(確定)按鈕,需要增加onclick鼠標點擊效果。
確定
當然如果希望輸入某個字段(如name=“uname”)后回車就需要在對應的input增加代碼
<input type="text" id="" name="uname" onkeypress="
if(event.keyCode==13){
record();//執行click事件,多個事件之間用英文的";"隔開
return false;//不執行表單提交
}"/>
以上可以實現用點擊按鈕或者回車實現提示信息為彈出對話框,點擊確定后才真正提交內容。
判斷所字段是否為空
方法二:舉個購物車提交的例子
用戶提交商品到購物車后不跳轉到購物車,直接返回原頁面并刷新該頁面
1、打開【include/common.fun.php】,找到
if($gourl=='' || $onlymsg==1)
{$msg = "<script>alert(\"".str_replace("\"","“",$msg)."\");</script>";
}
替換成:
if($gourl=='' || $onlymsg==1)
{$msg = "<script>alert(\"".str_replace("\"","“",$msg)."\");self.location=document.referrer;</script>";
}
2、打開【plus/posttocar.php】,找到
ShowMsg("已添加加到購物車,<a href='car.php'>查看購物車</a>","car.php");
替換成:
ShowMsg("已添加加到購物車,<a href='car.php'>查看購物車</a>");
DedeCMS跳轉提示信息修改總結
第一種是利用原生JavaScript與DedeCMS源代碼,功能較強大,可以對字段進行篩選、判斷是否空等操作,根據自己的實際需要進行修改;
另一種是只利用了DedeCMS源代碼,功能較單一。根據自己的實際需要選擇任意一種都可以,兩種方法有沖突。