zoukankan      html  css  js  c++  java
  • 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.

  • 相关阅读:
    关于如在本地虚拟机上linux系统上设置静态的ip地址
    编程规约(下)-阿里巴巴Java开发手册
    编程规约(上) -- 阿里巴巴Java开发手册
    eclipse项目导入到idea
    博客收藏
    springboot springcloud
    idea配置maven仓库
    理项目
    日志管理
    [置顶] 2016年终总结
  • 原文地址:https://www.cnblogs.com/honeynm/p/4181292.html
Copyright © 2011-2022 走看看