PowerBuilder與嵌入瀏覽器互動

來源:互聯網
上載者:User

準備工作
1. 新增一個Application應用,新增一個視窗。
2. 在視窗中新增一個OLE控制項:Microsoft Web Browser,命名為old_1。
3. 新增一個TextBox網址輸入控制項,命名為sle_url,初始值為c:\temp\index.html。
4. 新增一個Button控制項,命名為cb_go,clicked代碼如下:

ole_1.object.Navigate(sle_url.text)

5. 新增檔案c:\temp\index.html,內容如下:

<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 />

 

PB如何調用網頁中的指令碼?
1. 在視窗中新增一個Button按鈕:Invoke Javascript,代碼如下:

ole_1.object.document.parentWindow.sayhello("1122")

2. 注意這裡的大小寫問題。JS區分大小寫,PB不區分大小寫,PB調用時將函數全部轉化成了小寫。假設JS中的函數是sayHello(),PB調用方式原則上應該也是sayHello(),但PB實際上在執行時轉換成了全部小寫sayhello(),這樣JS在實際執行時就找不到sayhello()這個函數。所以,要想在PB中調用的JS函數應該全部都用小寫作為函數名。

PB如何擷取網頁元素?
1. 在視窗中新增一個Button按鈕:Fetch User Name,代碼如下:

messagebox('', string(ole_1.object.Document.GetElementById("user_name").InnerText))

 

PB如何修改網頁元素的屬性?
1. 在視窗中新增一個Button按鈕:Change User Name,代碼如下:

ole_1.object.Document.GetElementById("user_name").InnerText = 'Super Man'

 

PB如何調用網頁元素的事件?
1. 在視窗中新增一個Button按鈕:Click Link,代碼如下:

ole_1.object.Document.GetElementById("say_hello").Click()

 

PB如何響應網頁中的Click事件?
1. 在ole_1的clicked事件中寫入如下代碼:

string ls_tagName, ls_id, ls_hrefls_tagName=ole_1.object.document.activeElement.tagNameif upper(trim(ls_tagName))="A" then    ls_id = ole_1.object.document.activeElement.id     ls_href =ole_1.object.Document.activeElement.href         messagebox('', ls_tagName + '/' + ls_id + '/' + ls_href)        ole_1.object.Navigate(ls_href)end if

2. 當在網頁中點選連結時,事件處理就會傳到ole_1.clicked。

參考資料:
1. http://hi.baidu.com/starvv_w/blog/item/6264f7a23fef60b9caefd067.html
2. http://apps.hi.baidu.com/share/detail/2832257

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.