Sign in to follow this  
Followers 0
HeidiR

Displaying HTML in a control

8 posts in this topic

Hi All,

I'm trying to display some HTML in an IE object. I am able to successfully display google.com in the control but not some local html from a variable. Code below. Is this possible?

CODE
;Define

$oIE = ObjCreate("Shell.Explorer.2")

GUICtrlCreateObj($oIE, 1, 1, 500, 500)

;This works

$oIE.navigate("http://www.google.com")

;This does not work (page can not be displayed)

$html = "<html><head></head><body><b>test</b></body></html>"

$oIE.navigate($html)


HeidiRFind free applications, code examples and more on my site at:http://heidisdownloads.com/

Share this post


Link to post
Share on other sites



Hi All,

I'm trying to display some HTML in an IE object. I am able to successfully display google.com in the control but not some local html from a variable. Code below. Is this possible?

CODE
;Define

$oIE = ObjCreate("Shell.Explorer.2")

GUICtrlCreateObj($oIE, 1, 1, 500, 500)

;This works

$oIE.navigate("http://www.google.com")

;This does not work (page can not be displayed)

$html = "<html><head></head><body><b>test</b></body></html>"

$oIE.navigate($html)

AFAIK, the parameter must be a document/link not HTML code. Save the file first and link it.

Share this post


Link to post
Share on other sites

AFAIK, the parameter must be a document/link not HTML code. Save the file first and link it.

Thanks for the quick reply. Is there a way to display HTML code from a variable in Autoit without using an external html file?


HeidiRFind free applications, code examples and more on my site at:http://heidisdownloads.com/

Share this post


Link to post
Share on other sites

here the code from the help file that I modified to get it to work.

#include <GUIConstantsEx.au3>
#include <IE.au3>
#include <WindowsConstants.au3>

_IEErrorHandlerRegister ()

$sHTML = "<h1>Hello World!</h1>"

$oIE = _IECreateEmbedded ()
GUICreate("Embedded Web control Test", 640, 580, _
        (@DesktopWidth - 640) / 2, (@DesktopHeight - 580) / 2, _
        $WS_OVERLAPPEDWINDOW + $WS_VISIBLE + $WS_CLIPSIBLINGS)
$GUIActiveX = GUICtrlCreateObj($oIE, 10, 40, 600, 360)
$GUI_Button_Back = GUICtrlCreateButton("Back", 10, 420, 100, 30)
$GUI_Button_Forward = GUICtrlCreateButton("Forward", 120, 420, 100, 30)
$GUI_Button_Home = GUICtrlCreateButton("Home", 230, 420, 100, 30)
$GUI_Button_Stop = GUICtrlCreateButton("Stop", 340, 420, 100, 30)

GUISetState()       ;Show GUI
_IENavigate ($oIE, "")


_IEBodyWriteHTML ($oIE, $sHTML)

; Waiting for user to close the window
While 1
    $msg = GUIGetMsg()
    Select
        Case $msg = $GUI_EVENT_CLOSE
            ExitLoop
        Case $msg = $GUI_Button_Home
            _IENavigate ($oIE, $sHTML)
        Case $msg = $GUI_Button_Back
            _IEAction ($oIE, "back")
        Case $msg = $GUI_Button_Forward
            _IEAction ($oIE, "forward")
        Case $msg = $GUI_Button_Stop
            _IEAction ($oIE, "stop")
    EndSelect
WEnd

GUIDelete()

Exit

Share this post


Link to post
Share on other sites

See _IEDocWriteHTML

Dale


Free Internet Tools: DebugBar, AutoIt IE Builder, HTTP UDF, MODIV2, IE Developer Toolbar, IEDocMon, Fiddler, HTML Validator, WGet, curl

MSDN docs: InternetExplorer Object, Document Object, Overviews and Tutorials, DHTML Objects, DHTML Events, WinHttpRequest, XmlHttpRequest, Cross-Frame Scripting, Office object model

Automate input type=file (Related)

Alternative to _IECreateEmbedded? better: _IECreatePseudoEmbedded  Better Better?

IE.au3 issues with Vista - Workarounds

SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y Doesn't work needs to be ripped out of the troubleshooting lexicon. It means that what you tried did not produce the results you expected. It begs the questions 1) what did you try?, 2) what did you expect? and 3) what happened instead?

Reproducer: a small (the smallest?) piece of stand-alone code that demonstrates your trouble

Share this post


Link to post
Share on other sites

here the code from the help file that I modified to get it to work.

#include <GUIConstantsEx.au3>
#include <IE.au3>
#include <WindowsConstants.au3>

_IEErrorHandlerRegister ()

$sHTML = "<h1>Hello World!</h1>"

$oIE = _IECreateEmbedded ()
GUICreate("Embedded Web control Test", 640, 580, _
        (@DesktopWidth - 640) / 2, (@DesktopHeight - 580) / 2, _
        $WS_OVERLAPPEDWINDOW + $WS_VISIBLE + $WS_CLIPSIBLINGS)
$GUIActiveX = GUICtrlCreateObj($oIE, 10, 40, 600, 360)
$GUI_Button_Back = GUICtrlCreateButton("Back", 10, 420, 100, 30)
$GUI_Button_Forward = GUICtrlCreateButton("Forward", 120, 420, 100, 30)
$GUI_Button_Home = GUICtrlCreateButton("Home", 230, 420, 100, 30)
$GUI_Button_Stop = GUICtrlCreateButton("Stop", 340, 420, 100, 30)

GUISetState()       ;Show GUI
_IENavigate ($oIE, "")


_IEBodyWriteHTML ($oIE, $sHTML)

; Waiting for user to close the window
While 1
    $msg = GUIGetMsg()
    Select
        Case $msg = $GUI_EVENT_CLOSE
            ExitLoop
        Case $msg = $GUI_Button_Home
            _IENavigate ($oIE, $sHTML)
        Case $msg = $GUI_Button_Back
            _IEAction ($oIE, "back")
        Case $msg = $GUI_Button_Forward
            _IEAction ($oIE, "forward")
        Case $msg = $GUI_Button_Stop
            _IEAction ($oIE, "stop")
    EndSelect
WEnd

GUIDelete()

Exit
Thanks for your help Rental. I got it to work with your code!

HeidiRFind free applications, code examples and more on my site at:http://heidisdownloads.com/

Share this post


Link to post
Share on other sites

See _IEDocWriteHTML

Dale

Thanks DaleHohm. This looks helpful. I think I have two solutions now!


HeidiRFind free applications, code examples and more on my site at:http://heidisdownloads.com/

Share this post


Link to post
Share on other sites

Thanks HeidiR, I needed to not use IE.au3 because it wouldn't get past the obfuscator. Then I saw your post and saw I didn't even need it.

Mostly, I just want to have some nice html displayed instead of extended labels to explain how to do something. So I wrote an html file that goes along with the script. It could be a local file or a web page, but here's how I made it work for me:

#include 
$HTML = "http://google.com"

GUICreate("Test html", 400, 410)

;Create frame for html to show
Local $oIE = ObjCreate("Shell.Explorer.2")
GUICtrlCreateObj($oIE, 10, 10, 380, 280)
$oIE.navigate($HTML)
;End create frame for html to show

GUISetState(@SW_SHOW)

While 1
$msg = GUIGetMsg()
If $msg = $GUI_EVENT_CLOSE Then ExitLoop
WEnd

GUIDelete()

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0