Call JavaScript (1) in Delphi-reply to the question of "fancy"

Source: Internet
Author: User
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"> <Title> </title> </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
 
  
 
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.