VBTrain.Net Documentation

LmsApi2.GetJsInitialize Function

Returns JavaScript that calls the SCORM function LMSInitialize (SCORM 1.2) or Initialize (SCORM 1.3), or returns 0 if GetJsInitialize has already been called during the current session.

Overloads Public Function GetJsInitialize( _
ByVal checkForError As Boolean, _
ByVal includeScriptTags As Boolean, _
ByVal returnVarName As String _
) As String
Overloads Public Function GetJsInitialize( _
ByVal checkForError As Boolean, _
ByVal includeScriptTags As Boolean _
) As String

Parameters

checkForError
Boolean indicating whether or not to include error checking code in the JavaScript.
includeSciptTags
Boolean indicating whether or not to include error checking code in the JavaScript.
returnVarName
Name of the JavaScript variable that will hold the LMSInitialize (SCORM 1.2) or Initialize (SCORM 1.3) return value. The returnVarName parameter also serves as the prefix for any error checking variables, and as the prefix for the hidden field in which the return value is stored (<returnVarName>_hField). See Remarks below.

Remarks

The JavaScript from the GetJsApiLocate function must be added to your page prior to using the JavaScript from GetJsInitialize.

You can use the server side RegisterClientScriptBlock method to add the JavaScript from any LmsApi GetJs function to your HTML page.

The SCORM function LMSInitialize (SCORM 1.2) or Initialize (SCORM 1.3) should be called only once per session. To help avoid calling this more than once, GetJsInitialize will return 0 if it has already been called during the current session. To bypass this behavior, you can call ResetApi to set the number of calls to GetJsInitialize back to 0.

The JavaScript returned from GetJsInitialize will do all of the following:

Example

The following example assumes the VBTrain.WebTracking namespace has been imported. In this example, the LmsApi for the session is stored as a property (LmsApiObject) of the current class.

[Visual Basic]
Private Sub Page_Load(ByVal sender As System.Object, _
      ByVal e As System.EventArgs) Handles MyBase.Load

   If Not IsPostBack Then
      InitLmsApi()
      ' other code here
   End If

   ' other code here
End Sub


Private Sub InitLmsApi()
   Dim apiObject As New LmsApi2
   Dim js As String

   apiObject.Enabled = True
   apiObject.ScormVersion = ScormVersionEnum.Version_13
   Me.LmsApiObject = apiObject

   'locate
   js = apiObject.GetJsApiLocate()
   Me.RegisterClientScriptBlock("apiLocate", js)

   'initialize
   js = apiObject.GetJsInitialize(True, True)
   If js <> "0" Then        ' not yet initialized
      Me.RegisterClientScriptBlock("apiInitialize", js)
   End If
End Sub

See Also

LmsApi2 Class | LmsApi Members | GetJsApiLocate