Add a "OnClick" javascript event listener on Tabs - Scriptcase 9 - Scriptcase Low-code
Event listener across tabs - javascript
prevent default action for tab key in chrome?
enter - How to call function when I press tab key in javascript? - Stack Overflow
In window B you set a cookie and in window A you create a setTimeout function that every "x" milliseconds check if there are any new cookie.
Look at this: Javascript communication between browser tabs/windows
If window A is a parent of window B (A opened B) then it's possible to find the element and add event listener. Also you can use postMessage to communticate between windows.
input.keydown(function(event){
if (event.keyCode === 9) {
event.preventDefault();
}
})
On keyup is too late, you need to call the event on keydown. That worked for me.
Here's an article on how to detect chrome:
http://javascriptly.com/2008/09/javascript-to-detect-google-chrome/
And this question: Disable tab key on a specific div might help you on disabling the tab key. If you are able to combine both yourself, you've probably got it working.
The disable function would become something like:
$('.textarea').on('keyup mouseup', function(e) {
if(e.which == 9) { e.preventDefault(); }
});
e.which = 9 is the tab key according to the last link given. If you are able to wrap the browser detection around it yourself, I guess you've got your working example.
You can add an event listener to the document like so.
document.addEventListener('keyup', function(event) {
if (event.keyCode == 9) {
whenEmpty();
}
});
This will listen for any keyup (keyboard button released) events, and then in the if check what the keycode of the pressed button was. 9 is the keycode for Tab. If you want to pass the field to the function, you could also add the event listener to the input itself. Then access it with event.target
You can add a keyup listener on body or you can add listener on your table(just if you add tabindex attribute )
// event listener for keyup
function checkTabPress(e) {
if (e.keyCode == 9) {
//call your function whenEmpty()
}
}
var body = document.querySelector('body');
body.addEventListener('keyup', checkTabPress);
If I get you correctly, you want to know when a tab/window is effectively closed. Well, AFAIK the only way in JavaScript to detect that is to use either onunload or onbeforeunload events.
Unfortunately (or fortunately?), those events are also fired when you leave a site over a link or your browsers back button. So this is the best answer I can give, I don't think you can natively detect a pure close in JavaScript. Correct me if I'm wrong here.
From MDN Documentation
For some reasons, Webkit-based browsers don't follow the spec for the dialog box. An almost cross-working example would be close from the below example.
window.addEventListener("beforeunload", function (e) {
var confirmationMessage = "\o/";
(e || window.event).returnValue = confirmationMessage; //Gecko + IE
return confirmationMessage; //Webkit, Safari, Chrome
});
This example for handling all browsers.