我想使用关闭按钮停止重定向页面。现在,我遇到了这样的情况:用户单击注销按钮,并显示带有消息的模式,我向模式中添加了关闭按钮,当用户单击关闭按钮页面不重定向时,我想实现这一点。
我的代码是:
HTML
<li><a href="/logout" id="log"><i class="zmdi zmdi-power"></i> <span>Log out</span></a></li>
JS
$('#log').click(function (e) {
e.preventDefault();
$(".close").remove();
$(this).hide();
$(".content").append('<div class="card " ><div class="alert alert-danger alert-dismissible fade show al"><button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">×</span></button>Oh snap! <a href="#" class="alert-link">Change a few things up</a> and try submitting again.</div></div>');
setTimeout(function () {
window.location.href = "/logout";
}, 6000);
});
我的模态已关闭,但仍重定向我。有人可以帮我吗?
答案 0 :(得分:-1)
要使用“确定”按钮取消登出,您需要像这样更改代码:
public function login()
{
$this->load->view('back/login');
}
public function proseslogin_admin()
{
//Panggil Model
$this->load->model('M_user');
$username = $this->input->post('user');
$password = $this->input->post('password');
$cek = $this->M_user->cek_login($username,$password)->num_rows();
//cek kondisi nya apakah ada yang login atau tidak
if($cek > 0)//jika benar
{
}
else//jika salah
{
$this->session->set_flashdata('pesan','Maaf Username dan Password Salah !');
redirect('Admin/login');
}
}
现在只需用按钮调用var logoutTimer;
$('#log').click(function (e) {
e.preventDefault();
$(".close").remove();
$(this).hide();
$(".content").append('<div class="card " ><div class="alert alert-danger alert-dismissible fade show al"><button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">×</span></button>Oh snap! <a href="#" class="alert-link">Change a few things up</a> and try submitting again.</div></div>');
doLogout();
});
function doLogout(){
logoutTimer = setTimeout(function () { window.location.href = "/logout"; }, 6000);
}
function cancelLogout(){
clearTimeout(logoutTimer);
}
函数:
cancelLogout()
答案 1 :(得分:-1)
HTML:
如果您不更改href =“#”,则会启动重定向。将其更改为“#”将等待6秒钟,从而使您有时间在单击时终止重定向!
<li><a href="#" id="log"><i class="zmdi zmdi-power"></i> <span>Log out</span></a></li>
脚本
var timer;
function cancelRedirect(){
clearTimeout(timer)
}
$('#log').click(function (e) {
...
timer = setTimeout(function () {
window.location.href = "/logout";
}, 6000);
//On close click call cancelRedirect()
...
}