类似thinkphp成功、错误跳转
welcome.php
<?php
if (!defined('BASEPATH'))
exit('No direct script access allowed');
class Welcome extends CI_Controller {
public function __construct() {
parent::__construct();
$this->load->helper('url');
}
public function index() {
echo 'this is index function <br>';
echo anchor('welcome/wait', 'go url');
}
public function wait() {
$data['message'] = 'success';
$data['waitSecond'] = 3;
// $data['jumpUrl'] = $_SERVER['HTTP_REFERER'];//tp默认是用此方法跳转
// $data['jumpUrl'] = 'http://localhost/ci/wait/index.php';
$data['jumpUrl'] = site_url('/welcome/other');
$this->load->view('welcome_message', $data);
}
public function other() {
echo 'this other function ';
}
}
welcome_message.php
<!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Transitional//EN' 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd'>
<html>
<head>
<title>页面提示</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta http-equiv='Refresh' content='<?php echo $waitSecond; ?>;URL=<?php echo $jumpUrl; ?>'>
<style>
html, body{margin:0; padding:0; border:0 none;font:14px Tahoma,Verdana;line-height:150%;background:white}
a{text-decoration:none; color:#174B73; border-bottom:1px dashed gray}
a:hover{color:#F60; border-bottom:1px dashed gray}
div.message{margin:10% auto 0px auto;clear:both;padding:5px;border:1px solid silver; text-align:center; width:45%}
span.wait{color:blue;font-weight:bold}
span.error{color:red;font-weight:bold}
span.success{color:blue;font-weight:bold}
div.msg{margin:20px 0px}
</style>
</head>
<body>
<script type="text/javascript">
var time = <?php echo $waitSecond; ?>;
function timedCount()
{
if (time > 0)
{
document.getElementById("default").innerHTML = time;
}
time--;
}
setInterval("timedCount();", 1000);
</script>
<div class="message">
<div class="msg">
<span class="success"><?php echo $message; ?></span>
</div>
<div class="tip">
页面将在
<span class="wait" id="default" ></span>
秒后自动关闭,如果不想等待请点击 <a href="<?php echo $jumpUrl; ?>">这里</a> 关闭
</div>
</div>
</body>
</html>
挺好的示例 :)
涉及两个主要知识:
1. JS 的 setInterval方法
2. 使用html 的Refresh实现页面自动跳转 不错
页:
[1]