esdd24fr Posted December 19, 2005 Share Posted December 19, 2005 Hello,I found two methods about focus, focus() to set the focus and blur() to remove the focus, but i didn't find any method to know if an object has the focus or not.Is anybody tried to use a "hasFocus()" method in Javascript?If you have some idea, please help me.Tks, Emmanuel. Link to comment Share on other sites More sharing options...
aspnetguy Posted December 19, 2005 Share Posted December 19, 2005 use this var hasFocus = (object.focus());if(hasFocus){}else{} if the object has focus, hasFocus will equal true, if not it will be false. It's just that simple.good luck! Link to comment Share on other sites More sharing options...
esdd24fr Posted December 19, 2005 Author Share Posted December 19, 2005 Tks for you quick answer.But, if I use object.focus(), it will give the focus to my object, isn't it?So the if condition will always true, and my problem is still here... Link to comment Share on other sites More sharing options...
aspnetguy Posted December 19, 2005 Share Posted December 19, 2005 hmm...your right.try thisJavaScript var hasFocus = false;function setFocusState(focusState){ hasFocus = focusState;} HTML <object...onfocus="setFocusState(true)" onblur="setFocusState(false)" ...> then you can check the state of hasFocus when you need to kow if the object has focus. Link to comment Share on other sites More sharing options...
esdd24fr Posted December 19, 2005 Author Share Posted December 19, 2005 Oh yes, it's simple but efficient.Tks very much. Emmanuel. Link to comment Share on other sites More sharing options...
aspnetguy Posted December 19, 2005 Share Posted December 19, 2005 glad i could help Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now