I am showing a Confirmation modal popup where user can either select yes or no and when user clicks yes i want to show another modal popup
this is my script for confirmation:
<script type="text/javascript">
function openModalConfirm(message, header, url) {
$(<%= myModal.ClientID%>).modal('show');
$('#lblMasterMessage').html(header);
$('#lblMasterbodyMessage').html(message);
$('#<%= BtnYes.ClientID %>').attr('onclick', "$('#myModal').modal('hide');setTimeout(function(){" + $(sender).prop('href') + "}, 50);");
$(<%= myModal.ClientID%>).on('hidden.bs.modal', function (e) {
if (url != '') {
window.location = url;
}
});
return true;
}
</script>
and this is the moadal popup which i want to show after the above popup is shown
<script type="text/javascript">
function openModal(message, header, url) {
$('#myModal').modal('show');
$('#lblMasterMessage').html(header);
$('#lblMasterbodyMessage').html(message);
$('#myModal').on('hidden.bs.modal', function (e) {
if (url != '') {
window.location = url;
}
});
}
</script>
Related
Hi im having problem with my radmenu. I want it to click to open and not open as you hover. I have set the clicktoopen = "true" already. Now the problem is when i click, it navigate to the respective requested page but the menu doesn't close.
<script type="text/javascript">
function OnClientItemClicking(sender, args) {
if (args.get_item().get_isOpen() == true) {
args.set_cancel(true);
args.get_item().close();
}
else {
}
}
</script>
<script type="text/javascript">
function OnClientMouseOverHandler(sender, eventArgs) {
if (eventArgs.get_item().get_parent() == sender) {
sender.set_clicked(false);
}
}
function onClientItemClicked(sender, args) {
}
</script>
Hello i need a pop up message of confirmation when going to close browser/tab only, not when going to click on any link. In my code, it gave me pop up message when i close browser/tab as well as click on any link, which i don't want. I really have no idea how to do it. Can anyone please help me.
My code is-
<body>
<div id="copyright">
<div class="moduletable copyright ">
<div class="custom copyright">
<p>
<span class="copy">© Copyright 2008</span>
Inc. All rights reserved. </p>
</div>
</div>
</div>
</div>
</div>
<br class="clear" />
</div>
</div>
<script language="JavaScript">
window.onbeforeunload = bunload;
function bunload(){
dontleave="Are you sure you want to leave?";
return dontleave;
}
</script>
</body>
</html>
Try this:-
<body>
click here
<script language="JavaScript">
window.onbeforeunload = function () {
return "Are you sure?";
}
function prevent() {
window.onbeforeunload = function () { };
};
</script>
</body>
Your said event onbeforeunload works perfectly.
window.onbeforeunload = function(e) {
return 'Dialog text here.';
};
See it in action.
Tl/Dr
The below code will be completely pseudo-code describing the method you'll need to run through to get this to work.
The first step is that you'll need to add an identifier to all "internal" links within your site. For example, if your page is contact, and there is a link to that page form your home page, you need to distinguish between the types of pages.
function confirmExit() {
if (!internal_link) {
// random shit..
return message
}
}
var key = "internal_link";
window[key] = false;
var message = "Your custom message. Are you sure you want to blah?";
window.onbeforeunload = confirmExit;
internal_link = false;
$(document).ready(function () {
if (!window.location.origin) {
window.location.origin = window.location.protocol + "//" + window.location.hostname
}
$("a").each(function () {
if ($(this)[0].href.indexOf(window.location.origin) == 0) {
if ($(this).attr("onclick") == "undefined") {
$(this).attr("onclick", key + " = true")
} else {
if ($(this).attr("onclick")) {
var e = $(this).attr("onclick");
$(this).attr("onclick", e + " " + key + " = true")
} else {
$(this).attr("onclick", key + " = true")
}
}
} else {
if ($(this).attr("onclick") !== key + " = true" || $(this).attr("onclick") == "undefined") {
$(this).attr("onclick", key + " = false")
}
}
});
});
The above is what I've used previously and it's worked perfectly. Basically what it does is adds an attribute to internal links (links within your site), then when users navigate around your site, the onbeforeunload runs the confirmExit() function and checks if the internal_link is false, if so, it shows the message otherwise it navigates through the site.
Nothing work for me but I made it with some combinations of the above code and from other forums.
<script language="JavaScript">
window.onbeforeunload = function () {
return "Are you sure?";
};
$(document).ready(function () {
$('a').click(function () {
window.onbeforeunload = null;
});
$('form').submit(function () {
window.onbeforeunload = null;
});
});
</script>
The onbeforeunload event will be fired when you submit a form too, so we need to prevent the event.
I am using below javascript code. I want to stay on same page till user click on alert.
After click on alert page should redirect to SomePage.aspx
<script type="text/javascript">
function myFunction() {
alert("Some text...");
window.location = 'SomePage.aspx';
}
</script>
Please let me know what I missed here.
Thanks.
Instead of alert i think you need confirm box :-
<script type="text/javascript">
function myFunction() {
var conf = Confirm("Some text...");
if(conf == true){
window.location = 'SomePage.aspx';
}
else{ }
}
</script>
Try Like this
Script
<script type="text/javascript">
window.alert = function (al, $) {
return function (msg) {
al.call(window, msg);
$(window).trigger("okbuttonclicked");
};
}(window.alert, window.jQuery);
$(window).on("okbuttonclicked", function () {
redirect();
});
function redirect() {
window.location.href = "http://www.google.com";
}
function myFunction() {
alert("Some text...");
}
</script>
Html
<input type="button" onclick="myFunction()" value="Click" />
Note :- This function is execute on every alert ok button. But you also pass some additional parameter for preventing to execute.
And i also recommended to use confirm instead of this.
I am working on asp.net(c#).I try to add a javascript alert when a user tries to close the current tab in browser. The code is not working in Chrome.Please can any one help about this topic.
This is my code:
<script type="text/javascript">
window.onbeforeunload = function close_window() {
var r = confirm("Do you want to view other topics?");
if (r == true)
{
alert("You pressed OK!");
var Url = "http://stackoverflow.com/";
window.location = Url;
return false;
}
else
{
window.close();
}
}
Remove the () when you're calling the function.
It should be:
window.onbeforeunload = function close_window {
Actually, try this.
function close_window() {
...
}
window.onbeforeunload = close_window;
And yes--it's really bad practice.
Please check my code in Chrome Browser, if you hit refresh you will be prompted with 2 options.
Leave This Page and
Stay on This Page
When I click the 2. Stay on this page button it must activate my custom function displayMsg()
Can any one provide me solution?
<script type="text/javascript">
function displayMsg() {
alert('my text..');
}
</script>
<script type="text/javascript">
window.onbeforeunload = function(evt) {
var message = 'Please Stay on this page and we will show you a secret text.';
if (typeof evt == 'undefined') {
evt = window.event;
}
if (evt) {
evt.returnValue = message;
return message;
}
trace(evt);
}
</script>
use a timer to listening for change variable :
var vals=0;
function displayMsg() {
alert('my text..');
}
window.onbeforeunload = function evens(evt) {
var message = 'Please Stay on this page and we will show you a secret text.';
if (typeof evt == 'undefined') {
evt = window.event;
}
timedCount();
vals++;
if (evt) {
evt.returnValue = message ;
return message ;
}
trace(evt);
}
function timedCount()
{
t=setTimeout("timedCount()",100);
if(vals>0)
{
displayMsg();
clearTimeout(t);
}
}
You can use a combination of the onbeforeunload and onunload events, setting a timer in the former and clearing it in the latter:
var showMsgTimer;
window.onbeforeunload = function(evt) {
var message = 'Please Stay on this page and we will show you a secret text.';
showMsgTimer = window.setTimeout(showMessage, 500);
evt = evt || window.evt;
evt.returnValue = message;
return message;
}
window.onunload = function () {
clearTimeout(showMsgTimer);
}
function showMessage() {
alert("You've been trolled!");
}
This works because the onunload event never fires when the user chooses to stay on the page.
Please use these lines of code , it works properly.
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js">
</script>
<script type="text/javascript">
$(function(){
$(window).bind('beforeunload', function(){
return 'Your Data will be lost :(';
});
});
</script>