Notice: This website is an unofficial Microsoft Knowledge Base (hereinafter KB) archive and is intended to provide a reliable access to deleted content from Microsoft KB. All KB articles are owned by Microsoft Corporation. Read full disclaimer for more details.

How To Pass Parameters from HTML to ActiveX Documents


View products that this article applies to.

This article was previously published under Q188018

↑ Back to the top


Summary

When you are launching a Visual Basic 5.0 UserDocument under Internet Explorer, you may want to pass it some information. You cannot call public methods and properties of the UserDocument from within the HTML for two reasons. First, as soon as the UserDocument loads, the HTML page used to launch it is destroyed. Second, Internet Explorer does not consider UserDocuments safe for scripting.

This article shows you a technique to pass information to the UserDocument you are launching from within the launching HTML page.

↑ Back to the top


More information

You can pass parameters to the UserDocument you are launching as a query string using the question mark(?) in the URL. After passing the desired information using the question mark from the HTML, you can retrieve it in your UserDocument.

HTML File

Modify the Setup Wizard generated .htm file as described in Knowledge Base article 168431� (see REFERENCES section below). Append the parameters you are interested in to the URL using the question mark (?):
Location.Replace = "MyDoc.VBD?MyParametersStr"
The string ParameterStr is passed using the question mark above. The question mark (?) is typically used to pass query string information. In addition to using Location.Replace, you can also navigate using Location.HREF, Window.Navigate, or a simple <A> tag.

Please note that any information passed in a URL is restricted to "safe" characters.

UserDocument Code

To retrieve the parameters sent to the UserDocument from the launching .htm file, examine the Parent.LocationURL property from the Show event of the UserDocument. Since Parent.LocationURL returns the entire URL for the UserDocument, you will have to parse out the parameter information from it.

When using the file:// protocol the ? will be encoded to a %3F. If the URL is a relative one you are using the file:// protocol and Internet Explorer 4, then the question mark must be explicitly escaped to %3F for this to work. If it is not escaped, the parameter will not get passed on. Please note that any unsafe characters in the query string will be be escaped.

The launching htm can look like this:
<SCRIPT LANGUAGE="VBScript">
Sub Window_OnLoad()
   ' For relative URLs, ? should be explicitly escaped to %3F
   ' for Internet Explorer 4
   location.href = "userdocument1.vbd%3FMyParamString"

   ' For absolute file urls, the ? is automatically escaped to %3F
   location.href = "file://c:\Tests\userdocument1.vbd?MyParamString"
End Sub
</SCRIPT>
				

Here is an example of how the parameters can be retrieved in the UserDocument accounting for both the encoded and unencoded question mark:
Private Sub UserDocument_Show()
       Dim Param
       Dim P As Integer

       P = InStr(Parent.LocationURL, "%3F")
       If P > 0 Then
          Param = Mid$(Parent.LocationURL, P + 3)
       End If

       MsgBox "Got : " & Param
End Sub
				

↑ Back to the top


References

For additional information, please see the following articles in the Microsoft Knowledge Base:
168431� PRB: Launching VB5 ActiveX Documents from Internet Explorer
181674� BUG: File Protocol URLs Do Not Work Correctly with # Fragments

↑ Back to the top


Keywords: kbhowto, KB188018

↑ Back to the top

Article Info
Article ID : 188018
Revision : 3
Created on : 7/2/2004
Published on : 7/2/2004
Exists online : False
Views : 606