WebHTMLViewer Setfocus

I’m still trying to figure out some workarounds to meet WCAG accessibility standards. Specifically, this means trying to control an application using the keyboard and not a mouse. I’m having luck except for some sticking points with the WebHTMLviewer.

If I click on the WebHTMLViewer, I can scroll it using the arrow keys and space bar. However, if I use HTMLviewer.setfocus command, it doesn’t really seem to do have any effect and no keyboard shortcuts work.

Is there something that needs to be enabled in order for the WebHTMLviewer to accept the focus or is this just a limitation right now?

Thanks!

You are right, something is wrong there.

In the documentation, … what the code is meant to do …

Read there and explain, please. This have no sense to me.

IMHO: some basic information was lost (or forgotten).

Add this method to a module:

Public Sub SetFocusForced(extends viewer as WebHTMLViewer)
  var exec() as String
  exec.Add( "(function() {" )
  exec.Add( "  let viewer = document.getElementById('" + viewer.ControlID + "_frame');" )
  exec.Add( "  viewer.focus();" )
  exec.Add( "})();" )
  viewer.ExecuteJavaScript( String.FromArray( exec, "" ) )
End Sub

Call like:

HTMLViewer1.SetFocusForced

You can’t set the focus to any element within the iframe because that’s blocked by cross-origin security, but this should work for setting the focus to the iframe element and allow keyboard navigation by the user.

3 Likes