Can i detect/capture the Broswer Back button using javascript? [duplicate] - javascript

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
Is there a way to catch the back button event in javascript?
In my application,the user can enter data eithe add or modify those modification is saved into database using ajax.After all the modifications is completed in the screen then user will be finalized the data.In the time,user accediently click on Browser 'Back' Button.
So,what i need is,if user clicked without 'Update' button then if clicks the Browser 'Back' button.i want to shown the alert message.So,How to detect/capture the 'Back' Button.Please help me

You could use the window.onbeforeunload event

<body onunload="Unloader()">
<script type="text/javascript">
function Unloader() {
}
</script>

Related

Beforeunload event is not getting the custom message [duplicate]

This question already has answers here:
How can I override the OnBeforeUnload dialog and replace it with my own?
(12 answers)
Is it possible to display a custom message in the beforeunload popup?
(7 answers)
javascript onbeforeunload not showing custom message
(1 answer)
Closed 3 years ago.
I have this code :
$(window).bind("beforeunload", function() {
App.confirm('popup.cancel.confirmation.message', $('#confirm-import-modal'), true);
return "Do you really want to close?";
});
I have 2 questions about this piece of code :
I have always the message This page is asking you to confirm that you want to leave - data you have entered may not be saved., and I put the message Do you really want to close?
App.confirm show a popup, is possible to display only this popup whitout the confirm default popup from javascript ? Because now I have 2 popups, one default from javascript and another generate by App.confirm()
Thanks in advance.

How do i trigger a jquery event [duplicate]

This question already has answers here:
How to open a file / browse dialog using javascript?
(9 answers)
Closed 9 years ago.
i have this problem:
i have this code
if(ext!="rar") {
$('#myform').trigger('click');
}
and if the file extension of the chosen file is not rar, the file input should open the window again to choose another file, but this code does not seem to work. What should i do?
$("#btn").click(function()
{
var fu = $("#fu");
var ext = /[^.]+$/.exec(fu.val());
if (ext!="rar")
{
fu.trigger("click");
}
});
http://jsfiddle.net/tugpM/1/
Assuming that your form tag has the id myform, what you have done just triggers a click on the form (not even on the submit button of the form). Without the HTML, it is not possible to know what you are triggering the click on.
What you need to do is trigger the click on the submit button
$('#mysubmitbutton').click();
or trigger a form submit:
$('#myform').submit();

detect which button is clicked in confirming page navigation [duplicate]

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
Capturing result of window.onbeforeunload confirmation dialog
I want to make user confirm page navigation like that:
window.onbeforeunload = function(e) {
return "Note that any unsaved data will be lost";
};
however, I want to detect if user clicked "Stay in this page" to do something important.
So is there anyway to detect which button is clicked?
NB: I tried adding confirm in the onbeforeunload function but chrome block it.
There is no way to execute code right after the user decided to stay on the page.
You can use the onunload event to do something in case the user does not stay. If you want to send an AJAX request that's one of the few cases where async: false is appropriate.
Try like this
$(document).ready(function(){
$('body').live('click',function(){
$clicked = (this).attr("value");
alert($clicked);
});
})
Consider that your buttons value should be your message like:"Note that any unsaved data will be lost"

onclick submit button JSP [duplicate]

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
Multiple submit Button click problem?
Have a type=Submit button in a JSP. Requirement is to disable this button on click.
The basic requirement is to stop posting multiple requests of the same form if this button is clicked multiple times for the same form.
Thank You.
Even if you disable the submit button the user can still submit the form by pressing F5 or ctrl+F5 or even using Browser reload button.So disabling the submit button won't be of much use.
Why not use Post/Redirect/Get method.
The PRG pattern basically redirects the user to another page when it is Posted.
Hence now when the user reloads or tries to resubmit the form he is calling the Get method so the form is prevented from resubmission.
However this is also not fully secured approach.
Look here: http://www.developertutorials.com/tutorials/javascript/how-disable-submit-button-050416-1275/
I use a simple JS function you can invoke with onlick():
<script type="text/javascript">
var isSubmitted = false;
function safeSubmit(entityName) {
if (!isSubmitted) {
isSubmitted = true;
document.forms[0].submit;
}
}
</script>

How to disable mouse right click and ctrl+v & ctrl+c keypress using JavaScript [duplicate]

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
How do I disable right click on my web page?
I want to disable right click and Ctrl+V & Ctrl+C keypresses on a web page using JavaScript. I have a page where customers has to enter the enquiry details. I don't want them to copy some data and paste it in some fields. Anyone, please help me.
Try this:
Check this link Disabling-the-right-click-on-web-page
<script language="javascript">
document.onmousedown=disableclick;
status="Right Click Disabled";
Function disableclick(e)
{
if(event.button==2)
{
alert(status);
return false;
}
}
</script>

Categories

Resources