Work with web browser OLE from Powerbuilder

To manipulation Web Browser Control (OLE) from VB or Powerbuilder.

Here is a sample code of Powerbuilder.

[1] Work with ole_ie (OLE object)

// go to page; go home, back, forward
 ole_ie.object.navigate2( url )
 ole_ie.object.gohome()
 ole_ie.object.goback()
 ole_ie.object.GoForward()
// stop or refresh page
 ole_ie.object.Stop()
 ole_ie.object.Refresh()
// Page setup; preview and print.
 int OLECMDID_PRINT = 6
 int OLECMDID_PRINTPREVIEW = 7
 int OLECMDID_PAGESETUP = 8
 int OLECMDEXECOPT_DODEFAULT = 0
 int OLECMDEXECOPT_PROMPTUSER = 1
 int OLECMDEXECOPT_DONTPROMPTUSER = 2
ole_ie.object.ExecWB( OLECMDID_PAGESETUP, OLECMDEXECOPT_DONTPROMPTUSER, AsStatement! )
 ole_ie.object.ExecWB( OLECMDID_PRINTPREVIEW, OLECMDEXECOPT_DODEFAULT )

[2] work with ole_ie.object.document

int i, l
 string ls_text = ''
// show links
 ls_text = ''
 l = ole_ie.object.document.links.length
 for i = 0 to l -1
 ls_text += 'InnerHTML: ' +ole_ie.object.Document.Links[i].InnerHTML + '~r~n'
 next
 messagebox( 'links '+string(l), ls_text )
// get element
 ls_text = ole_ie.object.Document.GetElementById("subject").InnerHTML
 messagebox( 'GetElementById("subject").InnerHTML', ls_text )
// modify element
 ole_ie.object.Document.GetElementById("subject").InnerHTML = 'Changed from outside'
// show scripts
 ls_text = ''
 l = ole_ie.object.document.scripts.length
 for i = 0 to l -1
 ls_text += 'InnerHTML: ' +ole_ie.object.Document.scripts[i].InnerHTML + '~r~n'
 next
 messagebox( 'script '+string(l), ls_text )
// call javascript
 ole_ie.object.document.script.sayhello("call via script obj.")
 ole_ie.object.document.script.alert("direct call via script obj.")
 ole_ie.object.document.parentWindow.sayhello("call via parentWindow")
 ole_ie.object.document.parentWindow.alert('direct call internal function.')
// assign HTML
 ole_ie.object.Document.body.innerHTML = 'assign HTML from outside '

Reference Site:
Powerpage – A lightweight web browser for making Electron-like GUI app
Writing Your Own Web Browser
Use Internet Explorer
PowerBuilder中使用Microsoft Web浏览器控件
PowerBuilder与嵌入浏览器交互

發表留言

在 WordPress.com 建立免費網站或網誌.

向上 ↑