Changing an Elements innerHTML in TWebBrowser

I‘m unable to change the innerHTML of a javascript element, but i can change the id so i‘m not sure why it wont work.

i get OLE error 800A0258.

Any help will be great, thanks.

 

===========================

"innerHTML of a javascript element" ...uhm what?

first: all things you can access thru TWebBrowser is called DOM and im sure you want to set the property "innerHTML" of an HTML-(container)-tag. have you ensured that you accessed the object correctly? try your assigning out of delphi within a javascript block and see if that works. have you also tried "innerText" instead?

==================================

I cant remember the error.

this is how i dot it now

procedure DoUpdate;
var
  document: IHTMLDocument2;
  FE: IHTMLElement;
  Res:TResourceStream;
  Str:TStringStream;
  Tmp:String;
begin
  document:= frmMain.List.Document as IHTMLDocument2;
  FE:= document.scripts.item(0, ‘‘) as IHTMLElement;
  if (FE <> nil) and (FE.id <> JSv) then begin
    Res:= TResourceStream.CreateFromID(hInstance, 1, ‘TEXT‘);
    Str:= TStringStream.Create(‘‘);
    Res.Seek(0, 0);
    Str.CopyFrom(Res, Res.Size);
    Tmp:= ‘<script language=javascript id=‘+JSv+‘>‘;
    Tmp:= Copy(Str.DataString, Pos(Tmp, LowerCase(Str.DataString)), Pos(‘</script>‘, LowerCase(Str.DataString))-Pos(Tmp, LowerCase(Str.DataString))+9);
    Str.Free;
    Res.Free;
    FE.outerHTML:= ‘<br id=del>‘+Tmp;
    ((frmMain.List.Document as IHTMLDocument2).parentWindow).execScript(‘document.body.removeChild(document.getElementById("del"));‘, ‘JavaScript‘);
    Tmp:= ‘‘;
  end;
end;

JSv is the Script version.

=================================================

innerHTML does not apply to all elements. 

For details see: 

http://msdn.microsoft.com/library/default.asp?url=/workshop/author/dhtml/reference/properties/innerhtml.asp


"The property is read/write for all objects except the following, for which it is read-only: COL, COLGROUP, FRAMESET, HTML, STYLE, TABLE, TBODY, TFOOT, THEAD, TITLE, TR."

and 

"By definition, elements that do not have both an opening and closing tag cannot have an innerHTML property."

For example when you try to set innerHTML for an <IMG> (which has noc closing tag) the above ole-error may occur.

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。