When is LONGRANGE javascript object available

Please do not use to report errors- use your regional help desk.
Please mark posts as being for RPG or RDMLX (LANSA) developer.
To subscribe by email, display this forum, scroll to the end and select ‘Subscribe Forum’.
Post Reply
Siyaman
Posts: 10
Joined: Tue Nov 26, 2013 7:25 am

When is LONGRANGE javascript object available

Post by Siyaman »

In the Programming LongRange With JavaScript document most of the APIs use the LONGRANGE object to access the custom APIs. I'm developing an app on an iPad 2 with iOS 7 and found that the LONGRANGE object is not immediately available when the webview loads and hence all my resulting code did not execute. I ran a test using the following code and found that LONGRANGE was only available after the 3 second timeout.

Code: Select all

        <script type="text/javascript">
            setTimeout(function(){
                alert("After timeout " + typeof LONGRANGE);
            },3000);
        
            document.addEventListener("DOMContentLoaded", function(event) {
                alert("OnDOMLoad " + typeof LONGRANGE);
            });

             alert("Rightaway " + typeof LONGRANGE);

             // Output
             // Rightaway undefined
             // OnDOMLoad undefined
             // After timeout [object]
        </script>
Is there a LONGRANGE.ready function or something similar I can use to check when the LONGRANGE object is ready? Is there some other setting I can set to make LONGRANGE load faster?

Thank you,

Siyaman
Siyaman Sadagopan | Associate Consultant | LANSA, Inc. – Canada
Pablo
Posts: 11
Joined: Thu Apr 19, 2012 12:32 pm

Re: When is LONGRANGE javascript object available

Post by Pablo »

Hi Siyaman,

this feature was undocumented in RV15. Below is what's in the current documentation:

When does LONGRANGE object become available?

When the HTML page is loading, the LONGRANGE object may not be available to your code. It is therefore essential that you reference LONGRANGE object only after it has become available, otherwise JavaScript exception would occur and the execution of your script will terminate prematurely.
When the LONGRANGE object becomes available to you, LongRange will invoke a global callback function onLongRangeReady(). It is a good practice to always define this function in your code.
It’s a good idea to initially have your UI in disabled state (for example, buttons not clickable) to stop your user from inadvertently doing an action that would trigger a script code that references the LONGRANGE object before it becomes available. You would then enable your UI in the onLongRangeReady function.
Post Reply