[英]Javascript Alert and stay on the current page
I want to create some alert with javascript and if i press ok it will stay on the current page. 我想用JavaScript创建一些警报,如果我按OK,它将保留在当前页面上。 I have try but if i use below javascript it will give the alert and it move in other page.
我已经尝试过,但是如果我在javascript下面使用它,则会发出警报,并在其他页面中移动。
echo '<script type="text/javascript">
alert("Maps not available");
window.close();
</script>';
Please help :) 请帮忙 :)
Here is my detail code. 这是我的详细代码。
if ($decoded['VEHICLE']['RESULT'] == 'OK') {
$arr = $decoded['VEHICLE']['DATA'];
if ($arr != NULL) {
$encoded = json_encode($arr, JSON_NUMERIC_CHECK);
$decoded_again = json_decode($encoded, TRUE);
$line = array();
foreach($decoded_again as $item) {
array_push($line, $item['LAT'].','.$item['LON']);
}
return $line;
} else {
echo '<script type="text/javascript">
alert("Maps not available");
</script>';
}
} else {
redirect('Badvertisers/showMap', 'gpsidnotfound');
}
in earlier i use this method, it will stay on the current page, but with refreshing the page. 在较早的时候,我使用这种方法,它将保留在当前页面上,但是会刷新页面。
Modification of url helper 修改网址帮助程序
case 'tracknotfound' : echo "<script>alert('Maps not Available');
document.location.href='".$uri."'; </script>\n";
break;
and i put this one above controller 我把这个放在控制器之上
else {
redirect('Badvertisers/showMap', 'tracknotfound');
}
Just don't use window.close();
只是不要使用
window.close();
and after you press ok will remain the page. 在您按“确定”后,将保留该页面。
window.close();
will close the back after you press ok 按确定后将关闭后背
Use JavaScript's confirm()
: 使用JavaScript的
confirm()
:
echo '<script type="text/javascript">
checkConfirm = confirm("Maps not available");
if(!checkConfirm){
window.close(); //This will close the page if "ok" is not selected
}
</script>';
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.