Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
25
rated 0 times [  29] [ 4]  / answers: 1 / hits: 15940  / 12 Years ago, thu, april 5, 2012, 12:00:00

I'm really looking for something that works with all current popular browsers (IE9, Chrome, Firefox, Safari) and all the way back to IE8.



Although, I've been looking for a way to set focus on a Flash move object after it has lost focus, I've found that all historical ways of doing this fail. I assume it is yet another security issue.



So, I'm now looking for how to monitor change events of some sort for the document.activeElement (though change doesn't really occur).


More From » focus

 Answers
-1

While @James's answer above is correct. I've added more details to make it a completely working solution along with the use of focus event too.



<html>
<body>
<input type=text id=Text1 name =Text1 value=/>
<input type=text id=Text2 name =Text2 value=/>
<SELECT><OPTION>ASDASD</OPTION><OPTION>A232</OPTION></SELECT>
<INPUT TYPE=CHECKBOX id=Check1/>
<INPUT type=TEXT id=text3/>
<input type=radio/>
<div id=console> </div>
<textarea id=textarea1> </textarea>
<script>

var lastActiveElement = document.activeElement;

function detectBlur() {
// Do logic related to blur using document.activeElement;
// You can do change detection too using lastActiveElement as a history
}

function isSameActiveElement() {
var currentActiveElement = document.activeElement;
if(lastActiveElement != currentActiveElement) {
lastActiveElement = currentActiveElement;
return false;
}

return true;
}

function detectFocus() {
// Add logic to detect focus and to see if it has changed or not from the lastActiveElement.
}

function attachEvents() {
window.addEventListener ? window.addEventListener('focus', detectFocus, true) : window.attachEvent('onfocusout', detectFocus);

window.addEventListener ? window.addEventListener('blur', detectBlur, true) : window.attachEvent('onblur', detectBlur);
}

attachEvents();

</script>
</body>
</html>

[#86397] Wednesday, April 4, 2012, 12 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
makaylahk

Total Points: 166
Total Questions: 94
Total Answers: 117

Location: Gabon
Member since Sat, Jul 25, 2020
4 Years ago
;