admin管理员组文章数量:1418113
I have a button something like this what should I do?
<input type="button" value="Exit" onclick="JavaScript:window.location.href='../index'"/>
On Exit I am going to Other view..
On click on Exit I need to display popup window saying Are you sure you want to Exit? with Ok and Cancel buttons
anybody tell me out to do this?
thanks
I have a button something like this what should I do?
<input type="button" value="Exit" onclick="JavaScript:window.location.href='../index'"/>
On Exit I am going to Other view..
On click on Exit I need to display popup window saying Are you sure you want to Exit? with Ok and Cancel buttons
anybody tell me out to do this?
thanks
Share Improve this question edited Sep 20, 2010 at 17:37 kumar asked Sep 20, 2010 at 17:20 kumarkumar 2,94418 gold badges62 silver badges90 bronze badges3 Answers
Reset to default 2JavaScript:
<input type="button" value="Exit" onclick="confirmBox()" />
function confirmBox(){
if (confirm('Are you sure you want to Exit?')){
window.location.href = '../index'
}
}
jQuery:
<input type="button" value="Exit" id="exit" />
$('#exit').click(function(){
if (confirm('Are you sure you want to Exit?')){
window.location.href = '../index'
}
});
For an input:
<input type="submit" id="exitApplication" value="Exit"/>
Using jquery you can:
$("#exitApplication").click(function(){
var answer = confirm("Are you sure you want to exit?")
if(!answer){
//false when they click cancel
return false;
}
});
If you've this...
<input type="button" value="Exit" onclick="JavaScript:window.location.href='../index'"/>
... there are a couple of ways to achieve this.
Both Chris & Sarfraz solutions work. What you can do as well as to add a confirm(...)
dialog in the page's onbeforeunload
event.
<html>
<body>
Click this button to go to Google's homepage.
<input type="button" value="Exit" onclick="window.location.href='http://www.google.'">
<script type="text/javascript">
window.onbeforeunload = function() {
return "Are you sure?";
}
</script>
</body>
</html>
This will guarantee that, not only when the user clicks the Exit button, but also when s/he tries to navigate away from the page (For example, clicking the "Back" button in the browser.), onbeforeunload
event will be triggered, and prompt the user to make sure s/he really wants to leave the page.
confirm(...)
returns true
if the user says "Yes, I want to leave the page."
本文标签: javascripthow to show the popup message on Exit buttonStack Overflow
版权声明:本文标题:javascript - how to show the popup message on Exit button - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745281574a2651452.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论