Skip Navigation

Using SRW API within OnLoad event

Due technical reason SR360 API is injected just after page was loaded. Thus, when event OnLoad is called SR360 API is not available.

To use SR360 API during OnLoad event developer need to wait until SR360 API will be injected.

Following sample code shows how it can be done:

<script type="text/javascript">
function srwApiLoaded()
{
         window.alert("srw api is loaded:"+SrwOSGiApi);
}

var checkIsSrwApiLoaded = function (srwApiLoadedCallback)
{
    if ( typeof SrwOSGiApi !== 'undefined')
    {
            srwApiLoadedCallback();
    }
    else
    {
            window.setTimeout(function () {checkIsSrwApiLoaded(srwApiLoadedCallback)},100);
    }
}
</script>
<body onload="checkIsSrwApiLoaded(srwApiLoaded);">

In above sample, during OnLoad Event method checkIsSrwApiLoaded   is called with method srwApiLoaded as a callback argument.

Inside checkIsSrwApiLoaded method it checks if SR360 API is injected. If yes then calls callback srwApiLoaded method, otherwise recursively calls itself with a timeout until SR360 API became available.

Method srwApiLoaded   in its body contains logic needed to be executed during OnLoad event together with available SR360 API.