Expanding obout.com ASP.NET TreeView from Delphi WebBrowser

I have a website using this a treeview component:

http://www.obout.com/t2/ex_expand_levels.aspx

I need expand all nodes of the treeview.I DONT have the buttons (nor the functions) just the treeview itself. (Please find the code sample below)

I have loaded the page and able to send JavaScript to the website, but have not been able to simulate click on the "+" signs to expand a nodes. I have got several.

I would really like to see a simple example code if possible in Delphi.

The Delphi code I am using to exec the Javascript is the following:

My form got a WebBrowser, an Edit and a Button:

uses MSHTML;

procedure TForm1.ButtonJSButtonClick(Sender: TObject);
  { Make browser exec JS }
var
  Doc: IHTMLDocument2;      // current HTML document
  HTMLWindow: IHTMLWindow2; // parent window of current HTML document
  JSFn: string;             // stores JavaScipt function call
begin

  // Get reference to current document
  Doc := WebBrowser1.Document as IHTMLDocument2;
  if not Assigned(Doc) then
    Exit;
  // Get parent window of current document
  HTMLWindow := Doc.parentWindow;
  if not Assigned(HTMLWindow) then
    Exit;
  // Run JavaScript
  try
    JSFn := Edit1.Text;
    HTMLWindow.execScript(JSFn, 'JavaScript');
  except
    // handle exception in case JavaScript fails to run
    ShowMessage('Error running JavaScript |'+Edit1.Text+'|');
  end;
end;

Thanks in advance,

Zsolt

JavaScript:

<!--   ASP TreeView component   http://www.obout.com   -->



<LINK REL=stylesheet HREF="/_tree/treeStyle_Explorer/obout_treeview.css" > 
<SCRIPT LANGUAGE="JavaScript">
<!--
var op2, ob_tb, ob_url, selected_node_id;
function ob_wk(os, url) {
    var ot = os.parentNode.nextSibling.firstChild.nextSibling;
    var lensrc = (os.src.length - 8);
    var s = os.src.substr(lensrc, 8);
    if (s == "inus.gif") {
        ot.style.display = "none";
        os.src = "/_tree/treeStyle_Explorer/plusik.gif";
    }
    if (s == "usik.gif") {
        ot.style.display = "block";
        os.src = "/_tree/treeStyle_Explorer/minus.gif";
    if (url != "") {
        var s = os.parentNode.nextSibling.firstChild.nextSibling.innerText;
        if (s != "Loading ...") {
            return;
        }
        ob_url = url;
        ob_tb = os;
        window.setTimeout("ob_tm()", 100);
    }
    }
}

function ob_tm() {
    var xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
    xmlhttp.open("GET", ob_url, false);
    xmlhttp.send("");
    ob_tb.parentNode.nextSibling.firstChild.nextSibling.outerHTML = xmlhttp.responseText;
}

function ob_ft(e) {
    if (e.tagName == "TABLE" && e.className == "ob_zz") {
        if (typeof op2 != "undefined") {
            op2.style.backgroundColor = "transparent";
            op2.style.border = "0px solid #999999";
            op2.style.margin = "1px";
        }
        e.style.backgroundColor = "#E6E6E6";
        e.style.border = "0px solid #aaceeb";
        e.style.margin = "0px";
        op2 = e;
        selected_node_id = e.children(0).children(0).children(1).id;
    }
    else {
        ob_ft(e.parentNode);
    }
}

function ob_os(e){
    var os = e.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.children(0).children(0);
    if (os != null) {
    if ((typeof os != "undefined") && (os.tagName == "IMG")) {
        var lensrc = (os.src.length - 8);
        var s = os.src.substr(lensrc, 8);
        if ((s == "inus.gif") || (s == "usik.gif")) {
            e.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.children(0).children(0).click();
        }
    }
    else {
        ob_os(e.parentNode);
    }
}}

//-->
</SCRIPT>




<!--   ASP TreeView component   http://www.obout.com   -->



<div id="divTree" name="divTree" style="background:;background-image: url('');overflow-X:auto; overflow-Y:auto; width:; height:;"><table cellspacing=0 cellpadding=0 border=0 style="display:block;"><tr><td width=1 class=ob_ic><img class=ob_ic src='/_tree/treeStyle_Explorer/minus.gif' onclick="ob_wk(this, '')"></td><td><table cellspacing=0 cellpadding=0 border=0 class=ob_zz><tr><td width=1 class=ob_ic><img width=16 class=ob_ic src='/_tree/xpGlobe.gif'></td><td id=a0 onclick='ob_ft(this)' class=ob_td>Root</td></tr></table><table cellspacing=0 cellpadding=0 border=0 style="display:block;"><tr><td width=1 class=ob_ic><img class=ob_ic src='/_tree/treeStyle_Explorer/plusik.gif' onclick="ob_wk(this, '')"></td><td><table cellspacing=0 cellpadding=0 border=0 class=ob_zz><tr><td width=1 class=ob_ic><img width=16 class=ob_ic src='/_tree/folder.gif'></td><td id=b1 onclick='ob_ft(this)' class=ob_td><SPAN onclick='ob_os(this)'>TREE</SPAN></td></tr></table><table cellspacing=0 cellpadding=0 border=0 style="display:none;"><tr><td width=1 class=ob_ic><img class=ob_ic src='/_tree/treeStyle_Explorer/plusik.gif' onclick="ob_wk(this, '')"></td><td><table cellspacing=0 cellpadding=0 border=0 class=ob_zz><tr><td width=1 class=ob_ic><img width=16 class=ob_ic src='/_tree/xpHome.gif'></td><td id=c1 onclick='ob_ft(this)' class=ob_td><SPAN onclick='ob_os(this)'>Site1</SPAN></td></tr></table><table cellspacing=0 cellpadding=0 border=0 style="display:none;"><tr><td width=1 class=ob_ic>&nbsp;</td><td><table cellspacing=0 cellpadding=0 border=0 class=ob_zz><tr><td width=1 class=ob_ic><img width=16 class=ob_ic src='/_tree/xpPanel.gif'></td><td id=d1 onclick='ob_ft(this)' class=ob_td><input type=checkbox name=sIteID value=1_DD32B129-527A-42FA-A0D0-FE3C0ED65BC5><STRONG>Site1>Unit1</STRONG><input type=hidden name=sup_ value={DD32B129-527A-42FA-A0D0-FE3C0ED65BC5}></td><td align=right></td></tr></table></td></tr></table></td></tr><tr><td width=1 class=ob_ic><img class=ob_ic src='/_tree/treeStyle_Explorer/plusik.gif' onclick="ob_wk(this, '')"></td><td><table cellspacing=0 cellpadding=0 border=0 class=ob_zz><tr><td width=1 class=ob_ic><img width=16 class=ob_ic src='/_tree/xpHome.gif'></td><td id=c2 onclick='ob_ft(this)' class=ob_td><SPAN onclick='ob_os(this)'>Site2</SPAN></td></tr></table><table cellspacing=0 cellpadding=0 border=0 style="display:none;"><tr><td width=1 class=ob_ic>&nbsp;</td><td><table cellspacing=0 cellpadding=0 border=0 class=ob_zz><tr><td width=1 class=ob_ic><img width=16 class=ob_ic src='/_tree/xpPanel.gif'></td><td id=d2 onclick='ob_ft(this)' class=ob_td><input type=checkbox name=sIteID value=2_E6DC2021-F8E9-4FBE-93F5-79C953FA7BA8><STRONG>Site2>Unit2</STRONG><input type=hidden name=sup_ value={E6DC2021-F8E9-4FBE-93F5-79C953FA7BA8}></td><td align=right></td></tr></table></td></tr></table></td></tr><tr><td width=1 class=ob_ic><img class=ob_ic src='/_tree/treeStyle_Explorer/plusik.gif' onclick="ob_wk(this, '')"></td><td><table cellspacing=0 cellpadding=0 border=0 class=ob_zz><tr><td width=1 class=ob_ic><img width=16 class=ob_ic src='/_tree/xpHome.gif'></td><td id=c3 onclick='ob_ft(this)' class=ob_td><SPAN onclick='ob_os(this)'>Site3</SPAN></td></tr></table><table cellspacing=0 cellpadding=0 border=0 style="display:none;"><tr><td width=1 class=ob_ic>&nbsp;</td><td><table cellspacing=0 cellpadding=0 border=0 class=ob_zz><tr><td width=1 class=ob_ic><img width=16 class=ob_ic src='/_tree/xpPanel.gif'></td><td id=d3 onclick='ob_ft(this)' class=ob_td><input type=checkbox name=sIteID value=3_01B94E4C-A21A-4C76-920E-C2B9773CE2B8><STRONG>Site3>Unit3</STRONG><input type=hidden name=sup_ value={01B94E4C-A21A-4C76-920E-C2B9773CE2B8}></td><td align=right></td></tr></table></td></tr></table></td></tr></table></td></tr></table></td></tr></table></div>
<SCRIPT LANGUAGE="JavaScript"><!--
ob_ft(b1);
 //--></script>


<!--   ASP TreeView component   http://www.obout.com   -->
链接地址: http://www.djcxy.com/p/34988.html

上一篇: 虚拟TreeView提示不显示

下一篇: 从Delphi WebBrowser扩展obout.com ASP.NET TreeView