Interaction between PowerBuilder and embedded browsers

Source: Internet
Author: User

Preparations
1. Add an application and a new window.
2. Add an ole control in the window: Microsoft Web browser, named old_1.
3. added a textbox URL input control named sle_url and its initial value is C: \ temp \ index.html.
4. added a button control named cb_go and clicked.CodeAs follows:

 
Ole_1.object.navigate (sle_url.text)

5. added the file c: \ temp \ index.html with the following content:

 <  Script  Language  = "JavaScript"  >  Function  Sayhello (MSG) {alert (MSG );} </  Script  >  This is a PowerBuilder test page.  <  BR  />  Your name:  <  Span  ID  = "User_name"  > Ultra Man </  Span  > < BR  />  <  A  ID  = "Say_hello"  Onclick  = "Javascript: sayhello ('I am Web browser ');"  > Say hello </  A  > <  BR  />  <  A ID  = "Www_link"  Href  = "Http: // 192.168.14.155"  > Http: // 192.168.14.155 </  A  > <  BR  /> 

 

How does Pb call scripts on a webpage?
1. Add a new button in the window: invoke Javascript. The Code is as follows:

 
Ole_1.object.document.parent##sayhello ("1122 ")

2. Pay attention to the Case sensitivity issue. Javascript is case-sensitive and Pb is case-insensitive. When PB is called, all functions are converted to lowercase letters. Assume that the function in JS is sayhello (), and the Pb call method should also be sayhello () in principle, but Pb is actually converted to all lower case sayhello () during execution (), in this way, JS cannot find the sayhello () function during actual execution. Therefore, to call all JS functions in Pb, Use lowercase as the function name.

How does Pb obtain webpage elements?
1. Add a new button in the window: Fetch user name. The Code is as follows:

 
MessageBox ('', string (ole_1.object.document.getelementbyid (" user_name "). innertext ))

 

How does Pb modify the attributes of webpage elements?
1. Add a button in the window: Change User name. The Code is as follows:

 
Ole_1.object.document.getelementbyid ("user_name"). innertext = 'super man'

 

How does Pb call webpage element events?
1. Add a button in the window: Click link. The Code is as follows:

 
Ole_1.object.document.getelementbyid ("say_hello"). Click ()

 

How does Pb respond to click events on a webpage?
1. Write the following code in the clicked event of ole_1:

 
String ls_tagname, ls_id, ls_hrefls_tagname1_ole_1.object.doc ument. activeelement. tagnameif upper (TRIM (ls_tagname) = "A" then ls_id = ole_1.object.document.activeelement.id ls_href = inclumessagebox ('', ls_tagname + '/' + ls_id + '/' + ls_href) ole_1.object.navigate (ls_href) end if

2. When you click a link on a webpage, event processing will be passed to ole_1.clicked.

References:
1.Http://hi.baidu.com/starvv_w/blog/item/6264f7a23fef60b9caefd067.html
2.Http://apps.hi.baidu.com/share/detail/2832257

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.