Beforeunload event is not getting the custom message [duplicate] - javascript

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.

Related

How to redirect or load new PHP page from PHP using jquery? [duplicate]

This question already has answers here:
How do I redirect to another webpage?
(58 answers)
Closed 5 years ago.
I was trying to load new php page from one the PHP page using Jquery.
window.location = 'admin-editcp.php'; //no success
$(location).attr('href','admin-editcp.php'); // no success
Checked my browser JS is also enabled. I tried it with Mozila, IE and Chrome.
Then i manage site in dreamweaver and I checked it there via live preview and when i clicked in click event, it loads properly.
But not in the above two methods with 3 browser.
I am confuse that what is missing here????
What I have tried:
You can use 'location.href' for this
location.href = "admin-editcp.php";
You can use this :
jQuery('#id').on('click', function(){
// Perform your action on click here, like redirecting to a sign-up url
window.location='https://www.requiredpageurl.php';
});
You're allmost correct. It should be:
window.location.href = "admin-editcp.php";

jquery how to select other element that is inserted by other JS/jQuery [duplicate]

This question already has answers here:
Event binding on dynamically created elements?
(23 answers)
Closed 6 years ago.
I am running discourse and I am trying to modify what happens when one clicks the logout link, I do not want to modify discourse stock javascript...
There is an element elem1 that when clicked inserts another html menu with the logout link. So is it not present when $(document).ready.. is called. I need to modify what happens on elem2.click which is where the logout link is.
I want to do this...
$("#elem1").click(function() {
console.log("step1")
$("#elem2").click(function () {
console.log("step2")
..do my custom logout
})
})
but I think jquery is not finding it because it was not there when it first loaded.
Change to this
$("#elem2").on('click',function () {
console.log("step2")
..do my custom logout
})
or if you're using older jQuery:
$("#elem2").live('click',function () {
console.log("step2")
..do my custom logout
})

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();

Timed alert box pop up for website? [duplicate]

This question already has answers here:
JavaScript alert box with timer
(11 answers)
Closed 9 years ago.
For my website I would like an alert box message to appear 4 seconds after the page is opened. I cant figure out how to do this as the timed function works if a button is clicked but I would like the alert box to pop up automatically withoutt any user input/button and then shut when the user clicks "okay"...
Any ideas or posts related to this topic would be great help!
Thanks
<script type = "text/javascript">
window.onload=function(){setTimeout(showPopup,4000)};
function showPopup()
{
//write functionality for the code here
}
</script>
In it's most simple form:
setTimeout(function(){alert("Hello")},4000);
4000 = 4 seconds
If you want an alert to appear after a certain about time use this code:
setTimeout(function() { alert("Your Message"); }, time);

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

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>

Categories

Resources