织梦有一个短消息函数,用来显示友好的弹出信息,并可以设置跳转的地址,及跳转的时间。更重要的一点:可以显示出执行的进度,非常友好,很多情况我们需要一直执行某个任务时,就需要这个东西。
效果如下:
代码如下
header("Content-type:text/html; Charset=utf-8"); $index=(isset($_GET['i'])) ? $_GET['i'] :1; $total_old = 10; $total = (isset($_GET['t'])) ? ($total_old - $index) :$total_old; $sstime = (isset($_GET['sstime'])) ? $_GET['sstime'] : time(); /** * 短消息函数,可以在某个动作处理后友好的提示信息 * * @param string $msg 消息提示信息 * @param string $gourl 跳转地址 * @param int $onlymsg 仅显示信息 * @param int $limittime 限制时间 * @return void */ function ShowMsg($msg, $gourl, $onlymsg=0, $limittime=0) { $htmlhead = "<html>\r\n<head>\r\n<title>DedeCMS提示信息</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'>\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(\"<br /><div style='width:450px;padding:0px;border:1px solid #DADADA;'>"; $rmsg .= "<div style='padding:6px;font-size:12px;border-bottom:1px solid #DADADA;background:#DBEEBD'><b>DedeCMS 提示信息!</b></div>\");\r\n"; $rmsg .= "document.write(\"<div style='height:130px;font-size:10pt;background:#ffffff'><br />\");\r\n"; $rmsg .= "document.write(\"".str_replace("\"","“",$msg)."\");\r\n"; $rmsg .= "document.write(\""; if($onlymsg==0) { if( $gourl != 'javascript:;' && $gourl != '') { $rmsg .= "<br /><a href='{$gourl}'>如果你的浏览器没反应,请点击这里...</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; } $ttime = time() - $sstime; $ttime = number_format(($ttime / 60),2); //返回提示信息 $tjlen = $total_old>0 ? ceil( ($index/$total_old) * 100 ) : 100; $dvlen = $tjlen * 2; $tjsta = "<div style='width:200;height:15;border:1px solid #898989;text-align:left'><div style='width:$dvlen;height:15;background-color:#829D83'></div></div>"; $tjsta .= "总用时:$ttime 分钟<br/>完成总任务的:$tjlen %,继续执行任务..."; if($index < $total_old) { ShowMsg($tjsta,'1.php?i='.($index+1).'&t='.$total.'&sstime='.$sstime,0,100); exit(); }else{ ShowMsg("完成所有任务!,发送周报:$total_old 总用时:{$ttime} 分钟。","javascript:;"); exit(); }
下载demo: http://yunpan.cn/cmzqR99SrVfIv (提取码:6044)