• 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.

  • 相关阅读:
    tp5更改入口文件到根目录的方法分享
    Linux安装JBOSS
    JBOSS和WebLogic区别
    面向对象编程的思维方式
    Struts+Spring+Hibernate整合入门详解
    DB2 UDB V8.1 管理
    oracle与DB2的一些架构
    oracle和DB2的差异
    JDK和JRE的区别
    Linux安装weblogic
  • 原文地址:https://www.cnblogs.com/honeynm/p/4181292.html
Copyright © 2020-2023  润新知