Link to home
Start Free TrialLog in
Avatar of kudos2u
kudos2u

asked on

sending HTML to Internet Explorer

I have generated some html in vb that I want to open in a full instance of internet explorer. I want to do this without writing out a temorary htm file to the drive also if possible.

Kudos
Avatar of Éric Moreau
Éric Moreau
Flag of Canada image

Here is the way to send new text to a WebBrowser control:

Private Sub Command1_Click()
Dim strX As String

    strX = "<html>"
    strX = strX & "<head>"
    strX = strX & "<title>Test</title>"
    strX = strX & "</head>"
    strX = strX & "<body>"
    strX = strX & "<p>Hi.    "
    strX = strX & "</body>"
    WebBrowser1.Navigate "about:blank"
    WebBrowser1.Document.write strX
End Sub
ASKER CERTIFIED SOLUTION
Avatar of Éric Moreau
Éric Moreau
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
You can also use eary binding by setting a reference to Microsoft Internet Controls, here is an early binding example that can be used in a VB6 formless application.

Further, by using CreateObject to create an instance of IE see emoreau's example, you can give a VBS script file a user interface.

Sub Main()
Dim IE As SHDocVw.InternetExplorer

Dim m$
Set IE = New SHDocVw.InternetExplorer


IE.Visible = True
IE.Navigate2 "About|Blank"


With IE
.ToolBar = True
.StatusBar = False
.FullScreen = True
.Top = 0
.Left = 0
.Navigate "about:blank"
.AddressBar = False
'wait till document loaded
Do While IE.ReadyState <> 4
DoEvents
Loop

End With
   
IE.Document.Close

m = "<html><head><title>This is a gas</Title>" + vbCrLf
m = m & "<script type=""text/vbscript"" language=""vbscript"">" + vbCrLf
m = m & "Function Release()" + vbCrLf
m = m & "DIM FRM" + vbCrLf
m = m & "SET FRM=DOCUMENT.FORMS(""fred"")" + vbCrLf
m = m & "FRM(""JIM"").Value=""1""" + vbCrLf
m = m & "End Function" + vbCrLf
m = m & "</SCRIPT>" + vbCrLf
m = m & "</head>" + vbCrLf
m = m & "<Body><form name=""fred"">" + vbCrLf
m = m & "This is an example<br>" + vbCrLf
m = m & "<input type=""hidden"" size=""0"" id=""jim"" value=""0"">" + vbCrLf
m = m & "<input type=""button"" id=""kiss"" value=""Go Now"" onclick='VBScript:release()'>" + vbCrLf
m = m & "</FORM>" + vbCrLf
m = m & "</BODY>" + vbCrLf

IE.Document.write m$
IE.Visible = True

Dim frm

Set frm = IE.Document.Forms("fred")
Dim dv
Set dv = frm("jim")


Do
    If dv.Value = "1" Then Exit Do
    DoEvents
   
Loop
IE.Quit
Set IE = Nothing


End Sub