Problem Source: http://www.cnblogs.com/del/archive/2008/07/30/1256669.html#1272732
Source code download: http://files.cnblogs.com/del/Dephi-JavaScript.rar
In this example, the HTML file used for the test (contains three JS functions to be tested ):
<xmp style="color: #009933"> &lt;Title&gt; &lt;/title&gt; </xmp>
In this example:
Code File:
Unit unit1; interfaceuses windows, messages, sysutils, variants, classes, graphics, controls, forms, dialogs, stdctrls, olectrls, shdocvw; Type tform1 = Class (tform) webbrowser1: twebbrowser; button1: tbutton; button2: tbutton; button3: tbutton; Procedure upload (Sender: tobject); Procedure button1click (Sender: tobject); Procedure button2click (Sender: tobject ); procedure button3click (Sender: tobject); end; var form1: tform1; implementation {$ R *. DFM} procedure extract (Sender: tobject); var htmlpath: string; begin webbrowser1.left: =-webbrowser1.width; {hide webbrowser1} htmlpath: = extractfilepath (paramstr (0) + 'test.htm '; webbrowser1.navigate (htmlpath); end; Procedure tform1.button1click (Sender: tobject); var STR: variant; begin STR: = webbrowser1.oleobject.doc ument. parentwindow. jsstr2 ('20140901'); showmessage (STR); end; Procedure tform1.button2click (Sender: tobject); var num: variant; begin num: = webbrowser1.oleobject.doc ument. parentwindow. jsnum2 (4); showmessage (Num); end; Procedure tform1.button3click (Sender: tobject); begin webbrowser1.oleobject.doc ument. parentwindow. jsmsg ('abc'); {You can also do this:} webbrowser1.oleobject.document.parentwindow.exe cscript ('jsmsg ("abcdefg") ', 'javascript'); end.
Form file:
Object form1: tform1 left = 0 Top = 0 caption = 'form1' clientheight = 167 clientwidth = 280 color = clbtnface font. charset = default_charset font. color = clwindowtext font. height =-11 font. name = 'tahoma 'font. style = [] oldcreateorder = false position = podesktopcenter oncreate = formcreate pixelsperinch = 96 textheight = 13 object webbrowser1: twebbrowser left = 64 Top = 48 width = 154 Height = 97 taborder = 0 controldata = {4c000000eb0f0000060a0000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000000000000000 00000000000000000100000000000000000000000000000000000000} end object button1: tbutton left = 104 Top = 40 width = 75 Height = 25 caption = 'button1' taborder = 1 onclick = button1click end object button2: tbutton left = 104 Top = 81 width = 75 Height = 25 caption = 'button2' taborder = 2 onclick = button2click end object button3: tbutton left = 104 Top = 120 width = 75 Height = 25 caption = 'button3' taborder = 3 onclick = button3click endend