VBTrain.Net Documentation

LmsApi2.GetJsGetLessonLocationAndChangeInFrame Function

Returns JavaScript that calls the SCORM LMSGetValue (SCORM 1.2) or GetValue (SCORM 1.3) function to get the lesson location (cmi.core.lesson_location in 1.2 or cmi.location in 1.3), and then changes the location of the specified frame to the that value.

Public Function GetJsGetLessonLocationAndChangeInFrame( _ 
ByVal checkForError As Boolean, _
Optional ByVal frameRef As String = "parent.frames['main'].location", _
Optional ByVal returnVarName As String = "returnValue"
) As String

Parameters

checkForError
Boolean indicating whether or not to include error checking code in the JavaScript.
frameRef
Optional. Specification of the frame reference to change. This reference is set to the cmi.core.lesson_location (SCORM 1.2) or cmi.location (SCORM 1.3) value if that value is not null.
returnVarName
Optional. Name of the JavaScript variable that will hold the LMSGetValue (1.2) or GetValue (1.3)  return value.

Remarks

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

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

Example

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

This example demonstrates a technique for changing the page in the main frame using the JavaScript from the GetJsGetLessonLocationAndChangeInFrame function and then forcing a postback.

[Visual Basic]
Private Sub InitApi()
   Dim apiObject As New LmsApi2
   Dim js As String
   Dim sb As New StringBuilder
   Dim jsAndCrStr As String = String.Concat("{0}", CrLf)

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

   'locate
   js = apiObject.GetJsApiLocate()
   Me.RegisterClientScriptBlock("apiLocate", js)        ' register separately in case already there

   With sb
      'initialize
      js = apiObject.GetJsInitialize(False, True)
      If js <> "0" Then            ' not yet initialized
         .Append(js)
      End If
      'studentName
      'lesson_status
      .Append(apiObject.GetJsGetValue(GetValueEnum.learner_name, False, True, "studentName"))
      .Append(apiObject.GetJsGetValue(GetValueEnum.v13_completion_status, False, True, "statusVar"))
      'lesson_location
      .Append(apiObject.GetJsGetLessonLocationAndChangeInFrame(False, , "lessonLocation"))

      ' force postback
      .Append(String.Format(jsAndCrStr, "<script language='javascript'>"))
      .Append(String.Format(jsAndCrStr, "document.navBar.submit();"))
      .Append(String.Format(jsAndCrStr, "</script>"))
   End With
   Me.RegisterClientScriptBlock("initCode", sb.ToString)
End Sub

See Also

LmsApi2 Class | LmsApi Members | GetJsApiLocate | GetJsGetValue