Jump to content
Sign in to follow this  
zackrspv

_IEDocInsert() Help

Recommended Posts

zackrspv

So,

I have a script, that embeds an IE control into a GUI. I use custom HTML for the header which defines both the doc type, head, css styles, and includes basic body elements as well.

So far, so good, easy to work with, and very easy to manipulate if i needed too.

However, I want to be able to add rows to my table (<tbody> elements). However, whenever I use _IE* functions to control them, I get com errors.

I could use some help.

Here's the actual script:

#include <IE.au3>
#include <guiconstants.au3>
#include <constants.au3>
#include <guiconstantsex.au3>
Local $oWINDOW_ldiff = 143, $oWINDOW_mdiff = 800, $num = 1, $popup_ContentAreaMainBackgroundColor = 0xFF0000
$form = GUICreate("", 1024, 768, -1, -1)
GUISetState()
Global $oIE_left = $oWINDOW_ldiff + 17, $oIE_right = 54
$oIE_Width = $oWINDOW_mdiff - 150;680
$oIE_Height = 350
If $num = 1 Then
    $XT_oIE2 = _IECreateEmbedded()
    $Obj_RCV2 = GUICtrlCreateObj($XT_oIE2, 0, 0, 1, 1)
    _IENavigate($XT_oIE2, "about:blank")
    $head = DefineHead()
    $body = DefineBody()
    $doctype = '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">'
    _IEDocWriteHTML($XT_oIE2, $doctype & "<HTML dir=ltr lang=en><HEAD>" & $head & "</HEAD><body>" & $body & "</body></html>")
    $oBody2 = _IETagNameGetCollection($XT_oIE2, "body", 0)
    GUICtrlSetPos($Obj_RCV2, 0, 0, 1024, 768)
EndIf
ConsoleWrite(_IEDocReadHTML($oBody2) & @CRLF)

_IEErrorHandlerRegister("MyErrFunc")
$oBody2 = _IETagNameGetCollection($XT_oIE2, "tbody", 0)
$sAppend = '<tr class="odd">'
$sAppend = $sAppend & '<th scope="row" id="r96"><a href="index.php?css=96#r96">Maniac Merchants</a></th>'
$sAppend = $sAppend & '<td><a href="http://www.marvmerchants.com">Marten Willberg</a></td>'
$sAppend = $sAppend & '<td>Germany</td>'
$sAppend = $sAppend & '<td>A Georgia headline with a green-blue body.</td>'
$sAppend = $sAppend & '<td><a href="http://www.marvmerchants.com/merchants.css" title="Download the Maniac Merchants CSS file">Download</a></td>'
$sAppend = $sAppend & '</tr>'
_IEDocInsertHTML($oBody2, $sAppend)
_IEErrorHandlerDeregister ()

Func MyErrFunc()
  ; Important: the error object variable MUST be named $oIEErrorHandler
    $ErrorScriptline = $oIEErrorHandler.scriptline
    $ErrorNumber = $oIEErrorHandler.number
    $ErrorNumberHex = Hex($oIEErrorHandler.number, 8)
    $ErrorDescription = StringStripWS($oIEErrorHandler.description, 2)
    $ErrorWinDescription = StringStripWS($oIEErrorHandler.WinDescription, 2)
    $ErrorSource = $oIEErrorHandler.Source
    $ErrorHelpFile = $oIEErrorHandler.HelpFile
    $ErrorHelpContext = $oIEErrorHandler.HelpContext
    $ErrorLastDllError = $oIEErrorHandler.LastDllError
    $ErrorOutput = ""
    $ErrorOutput &= "--> COM Error Encountered in " & @ScriptName & @CR
    $ErrorOutput &= "----> $ErrorScriptline = " & $ErrorScriptline & @CR
    $ErrorOutput &= "----> $ErrorNumberHex = " & $ErrorNumberHex & @CR
    $ErrorOutput &= "----> $ErrorNumber = " & $ErrorNumber & @CR
    $ErrorOutput &= "----> $ErrorWinDescription = " & $ErrorWinDescription & @CR
    $ErrorOutput &= "----> $ErrorDescription = " & $ErrorDescription & @CR
    $ErrorOutput &= "----> $ErrorSource = " & $ErrorSource & @CR
    $ErrorOutput &= "----> $ErrorHelpFile = " & $ErrorHelpFile & @CR
    $ErrorOutput &= "----> $ErrorHelpContext = " & $ErrorHelpContext & @CR
    $ErrorOutput &= "----> $ErrorLastDllError = " & $ErrorLastDllError
    ConsoleWrite($ErrorOutput & @CRLF)
    SetError(1)
    Return
EndFunc;==>MyErrFunc

While 1
    $msg = GUIGetMsg()
    Switch $msg
        Case $gui_event_close
            Exit
    EndSwitch
WEnd

Func DefineBody()
    $body = ""
    $body = FileRead("test.html")
    Return $body
EndFunc ;==>DefineBody

Func DefineHead()
    $head = ""
    $head = $head & '<meta http-equiv="Content-Type" content="text/html; charset=us-ascii">'&@CRLF
    $head = $head & '<style type="text/css">' & @CRLF
    $head = $head & FileRead("tab2.css")&@CRLF
    $head = $head & '</style>'&@CRLF
    Return $head
EndFunc ;==>DefineHead

Here's the resut:

<HTML dir=ltr lang=en><HEAD>
<META content="text/html; charset=us-ascii" http-equiv=Content-Type>
<STYLE type=text/css>

table {
     font-family:verdana, arial, sans-serif;
    border-collapse:collapse;
    border-spacing:0;
    margin:0 0 1em;
    color:#000;
    font-size:0.75em;
    width:100%
    }
table a {
    color:#523A0B;
    text-decoration:none;
    border-bottom:1px dotted;
    }
table a:visited {
    color:#444;
    font-weight:normal;
    }
table a:visited:after {
    content:"\00A0\221A";
    }
table a:hover {
    border-bottom-style:solid;
    }
thead th,
thead td,
tfoot th,
tfoot td {
    border:1px solid #523A0B;
    border-width:1px 0;
    background:#EBE5D9;
    }
th {
    font-weight:bold;
    line-height:normal;
    padding:0.25em 0.5em;
    text-align:left;
    }
tbody th,
td {
    padding:0.25em 0.5em;
    text-align:left;
    width:auto;
    vertical-align:top;
    }
tbody th {
    font-weight:normal;
    white-space:nowrap;
    width:auto;
    }
tbody th a:link,
tbody th a:visited {
    font-weight:bold;
    }
tbody td,
tbody th {
    border:1px solid #fff;
    border-width:1px 0;
    }
tbody tr.odd th,
tbody tr.odd td {
    border-color:#EBE5D9;
    background:#F7F4EE;
    }
tbody tr:hover td,
tbody tr:hover th {
    background:#ffffee;
    border-color:#523A0B;
    }
caption {
    font-family:Georgia,Times,serif;
    font-weight:normal;
    font-size:1.4em;
    text-align:left;
    margin:0;
    padding:0.5em 0.25em;
    }
</STYLE>
</HEAD>
<BODY>
<DIV id=itsthetable>
<TABLE summary="Submitted table designs">
<THEAD>
<TR>
<TH scope=col>Design Name</TH>
<TH scope=col>Author</TH>
<TH scope=col>Country</TH>
<TH scope=col>Comment</TH>
<TH scope=col>Download</TH></TR></THEAD>
<TBODY id=tbody></TBODY></TABLE></DIV></BODY></HTML>
--> COM Error Encountered in cpos.au3
----> $ErrorScriptline = 2463
----> $ErrorNumberHex = 80020009
----> $ErrorNumber = -2147352567
----> $ErrorWinDescription = ??????????????
----> $ErrorDescription = Invalid target element for this operation.
----> $ErrorSource = htmlfile
----> $ErrorHelpFile = C:\Windows\SysWOW64\mshtml.hlp
----> $ErrorHelpContext = 0
----> $ErrorLastDllError = 0

Note, the about line number is actually from _IE* include. It's the

Case $s_where = "beforeend"
    $o_object.insertAdjacentHTML($s_where, $s_string)
    SetError($_IEStatus_Success)
    Return 1

block of the _IEDocInsertHTML() function. It fails on the $o_object.insertAdjacentHTML($s_where, $s_string) function with 'Action failed'.

How can I insert the $sappend HTML into the actual <tbody> element w/o it erroring out?

Note, i HAVE tried the _IEPropertyGET(*) functions, and it returns the hTML for the <tbody> element, but when trying to use _IEPropertySET() for the innerhtml, it gives yet another com error. It just doesn't want to insert into that tbody element.

I know that, for the most part, <tbody> isn't required, but it makes the code easier to read, especially as i'll be adding headers and footers (<thead> and <tfoot>) into this eventually.

My ultimate goal is to be able to make a dynamic table that I can inject rows into as the information is recieved.

Any help would be appriciated :)

test.html

tab2.css

Edited by zackrspv

-_-------__--_-_-____---_-_--_-__-__-_ ^^€ñ†®øÞÿ ë×阮§ wï†høµ† ƒë@®, wï†høµ† †ïmë, @ñd wï†høµ† @ †ïmïdï†ÿ ƒø® !ïƒë. €×阮 ñø†, bµ† ïñ§†ë@d wï†hïñ, ñ@ÿ, †h®øµghøµ† †hë 맧ëñ§ë øƒ !ïƒë.

Share this post


Link to post
Share on other sites
DaleHohm

It would be helpful if you would simplify your issue before posting. No need for the embedding or the CSS or the complex table. Here's a 4-line reproducer:

#include <IE.au3>

$oIE = _IE_Example("table")
$oTable = _IEGetObjByName($oIE, "tableOne")
_IEDocInsertHTML($oTable, '<tr><td colspan=6>wide</td></tr>')

For reasons I don't understand, insertAdjacentHTML is not supported for tables (perhaps because these special methods below exist):

#include <IE.au3>

$oIE = _IE_Example("table")
$oTable = _IEGetObjByName($oIE, "tableOne")
$oNewTR = $oTable.insertRow(-1) ; last row

$oNewCell0 = $oNewTR.insertCell(0)
$oNewCell1 = $oNewTR.insertCell(1)
$oNewCell2 = $oNewTR.insertCell(2)
$oNewCell3 = $oNewTR.insertCell(3)
$oNewCell4 = $oNewTR.insertCell(4)
$oNewCell5 = $oNewTR.insertCell(5)
_IEPropertySet($oNewCell0, "innerText", "un")
_IEPropertySet($oNewCell1, "innerText", "deux")
_IEPropertySet($oNewCell2, "innerText", "trois")
_IEPropertySet($oNewCell3, "innerText", "quatre")
_IEPropertySet($oNewCell4, "innerText", "cinq")
_IEPropertySet($oNewCell5, "innerText", "six")

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
zackrspv

It would be helpful if you would simplify your issue before posting. No need for the embedding or the CSS or the complex table. Here's a 4-line reproducer:

Dale

Thanks Dale :) I'll see if i can adapt this, souldn't be too hard :P I was reading through the DOM and MSDN and I think that method will work nicely.

The reason why i included so much in the initial post, evn as it was over the top, was becasue i dont like being told i dont include enough information. I'd rather provide TONS of information and have a short answer, than be asked/flamed for not providing enough :)

As it is, you are by far one of my fav helpers on this board, helped me may times with the _IE() functions ;)

Thanks for this one too ;)


-_-------__--_-_-____---_-_--_-__-__-_ ^^€ñ†®øÞÿ ë×阮§ wï†høµ† ƒë@®, wï†høµ† †ïmë, @ñd wï†høµ† @ †ïmïdï†ÿ ƒø® !ïƒë. €×阮 ñø†, bµ† ïñ§†ë@d wï†hïñ, ñ@ÿ, †h®øµghøµ† †hë 맧ëñ§ë øƒ !ïƒë.

Share this post


Link to post
Share on other sites
DaleHohm

I understand not wanting to be flamed for too little information, but I wasn't about to try to troubleshoot with what you provided this time -- way too many variables. Please see the description of a "reproducer" in my sig. That's what I created in this case and I would prefer you do that work.

Thanks for the kudos, glad to help.

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

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  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.