Set focus to Web page input on session switch

Version 1

    Verified Product Versions

    Wavelink Naurtech CETerm 5.7

    When you switch from a terminal emulation session to a web browser session, the cursor focus does not end up at the input field on the web session form. This sample script demonstrates how to force this input focus.

     

    This script is specific to SAP WebConsole. It is fired automatically when the session is switched. It looks at the web page to decide where to place the focus. It looks through the document object for the HTML page to find input / edit elements. If found, it gives that element keyboard input focus.

     

    // OnSessionSwitch

    //

    // SAP - set to last focus location on session switch

    //

    function OnSessionSwitch( session, previousSession )

    {

        var document = CETerm.Session( session ).Browser.Document;

     

       if (document != null &&

            document.form1 != null &&

            document.form1.FOCUS != null)

        {

            function setFocus( index )

            {

               // Look for valid edit element

                var element = "document.form1.edit_" + index;

     

                if (eval( element ) != null)

                {

                    // Set focus to element

                    eval( element + ".focus();" );

                    return 1;

                }

     

               // Look for valid pswrd element

                element = "document.form1.pswrd_" + index;

     

                if (eval( element ) != null)

                {

                   // Set focus to element

                    eval( element + ".focus();" );

                    return 1;

                }

     

                return 0;

            }

     

            // Look for valid field index

            var index = document.form1.FOCUS.value;

            if (index > 0)

            {

               // Have valid index

                setFocus( index );

            }

            else

            {

               // Set to first valid field

                var i = 1;

                while (setFocus(i) == 0 && i < 9)

                {

                    i++;

                }

            }

        }

    }