[VB] 在WebBrowser中執行JavaScript

摘要:[VB] 在WebBrowser中執行JavaScript

 

在VB6使用WebBrowser時,如果要執行JavaScript的話可以使用Navigate 方法,這個方法就類似在網頁瀏覽器的網址列輸入Script並執行一樣,範例如下:
WebBrowser1.Navigate "javascript: (function(){alert('hello, world');})();"
 
另外也可以使用Document.parentWindow.execScript來執行JavaScript或VBScript,範例如下:
WebBrowser1.Document.parentWindow.execScript "alert('hello, world');", "JavaScript"
WebBrowser1.Document.parentWindow.execScript "msgbox(""hello, world"")", "VBScript"
如果第二個參數省略的話,則是會當成JavaScript執行
WebBrowser1.Document.parentWindow.execScript "alert('hello, world');"

文章內容僅提供技術分享,如有錯誤還請不吝指教。