function back(){
document.getElementById("xbox").addEventListener("click",closePage);
function closePage(){
window.close()
}
}
i am using this code for closing the application which i have connected to html page in button "oncliick="back()" "
I was trying to close the application with above code but it is getting close but on second click of the mouse . and i want it to be close on first click of mouse.
Related
now im doing laravel project. i want to implement javascript code only for preventing the back button and close tab window. i read the article that we can use onbeforeunload(). but this code not suitable with me. because the warning message will display when i want to go to another link menu on my site..
here is my code
window.onbeforeunload = function() {
return "Do you really want to leave?";
};
above code still have problem to me :
i must click at list 1 time on the side. then click close tab, so the pop up will display. if i dont click, the pop up not display and directly close the tab.
im using opera browser but the custom message not display same as what i type. it display "Changes you made may not be saved.". How do i could display the sentence as same as i type?
is there any other code that just prevent only for back button and close the tab? so went i want to navigate to other link menu on my site, the warning message not display.
please help
//you should $event.return = "";
window.addEventListener("beforeunload", function ($event) {
return $event.returnValue = "";
})
I am new to javascript .I want to have a javascript code that allow to open new tab for a link just once when you click on either buttons but when you click on same button or other button , the script wont work .For example : After clicking on the download or printing button I want to open new tab of my facebook page but I want to do it just once , so if that user clicked on download button that's it .So even if he clicks on same button multiple times or other print button multiple times the facebook function wont work at all
function facebook() {
window.open("https://www.facebook.com");
}
<button onclick="facebook();printContent('exportContent')" >Print</button>
<button onclick="facebook();Download();" >Download</button>
I tried to use this.onclick=null in the buttons but it cause two problems : 1/ It make other functions just work once while I want other functions to keep working each time the buttons are clicked and facebook function to work just once ; 2/ when click on one of the buttons new tab opens and when you click on other button it still open too .
You can create a global variable to keep track of how many times you invoked facebook function
var counter = 0;
function facebook() {
if(counter === 0) {
window.open("https://www.facebook.com");
counter += 1;
}
}
function Download() {
console.log('dl')
}
function printContent(msg) {
console.log(msg)
}
<button onclick="facebook();printContent('exportContent')" >Print</button>
<button onclick="facebook();Download();" >Download</button>
I have two applications webApp1 and webApp2. In webApp1 , HTML page contains an tag on click of it an HTML page in webApp2 will be opened in new browser window, page contains one text box and save button. If user enters something in text box and click on save button, need to send a notification from webApp2 to webApp1 so that webApp1 can close the newly opened window and perform some operation after closing window.
How can I achieve this using Java script?
What you are looking for is window.opener.
In Webapp1, window 1, you would have a function in javascript that would need to be done after closing.
function AfterClose() {
// code to execute in Webapp1, triggered in Webapp2
}
In Webapp2, within your save function, do the following.
function Save() {
// ...
// code to save your information
// ...
window.opener.AfterClose();
self.close();
}
Why not just call window.close() as part of the save button click function in webapp2?
I would like to know how I can display an javascript alert in the following 3 conditions:
the reload button from the browser is clicked
Reloading the page with a keybort shortcut (e.g. CMD + R)
Leaving the actual page by clicking on links on the page.
The user should be able to cancel the reload in the alert window.
try onbeforeunload which opens a prompt box for the user
window.onbeforeunload = function() {
return "noooooo... dont go";
}
the return value will be displayed as the prompt text, if the user clicks the confirm button, the window continues with the navigation - and stops the navigation if the user chooses cancel
example in action
I'm new to html& jquery. I'm having a dialog and while trying to close it, I need to ask a confirmation message, which should be displayed on top of the existing dialog. I tried using jconfirmation, but it comes up after closing the existing dialog. But I need the confirmation to come on top of the existing dialog. How can I do it?
$("#ref").load('myTest.html').dialog({
create:function(e,u) {
// ETC
},
close:function(e,u){
//ADD CODE TO SHOW CONFIRMATION ON TOP
}
});
Hi Dialog will fire close callback after it is closed. Try using beforeClose event. You should be able to use the same call back that you are using for close with it
$("#ref").load('myTest.html').dialog({
create:function(e,u) {
// ETC
},
beforeClose:function(e,u){
//ADD CODE TO SHOW CONFIRMATION ON TOP
}
});
http://docs.jquery.com/UI/API/1.8/Dialog#event-beforeClose