Jump to content

Recommended Posts

Posted (edited)

How can I check if element is focused in Firefox using FF.au3 UDF?

This is my try:

I have prepared a function that checks if the object is focused:

 

_FFCmd('FFau3.isfocused=function isfocused(a){try{return (a === document.activeElement)}catch(e){return}}')

$oElm = _FFXPath("//*[@id='someId']")
ConsoleWrite(_FFIsFocused($oElm))

Func _FFIsFocused($sElement = "")
    Local $isFoc = _FFCmd("FFau3.isfocused(" & $sElement & ")")
    Return $isFoc
EndFunc   ;==>_FFIsFocused

Now, the javascript part is tested and it does return successfully.

After a lot of try/fails I inserted an alert box in order to display the object being compared.

Here is what I got

 

The focused object is: [object XULElement]

The object that I send for comparing is [object HTMLInputElement]

Why is that?

 

 

Edited by milos83
Posted
4 minutes ago, Danp2 said:

Have you tried comparing to

FFau3.WCD.activeElement

instead of

document.activeElement

?

You nailed it!

Thank you Danp2!

 

I'm new to FF.au3 so I didn't know this is the right way to access the document.

 

 

The final working code is

_FFCmd('FFau3.isfocused=function isfocused(a){try{return (a === FFau3.WCD.activeElement)}catch(e){return}}')

$oElm = _FFXPath("//*[@id='someId']")
ConsoleWrite(_FFIsFocused($oElm))

Func _FFIsFocused($sElement = "")
    Local $isFoc = _FFCmd("FFau3.isfocused(" & $sElement & ")")
    Return $isFoc
EndFunc   ;==>_FFIsFocused

 

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...