1,502
社区成员




<html>
<head>
<script language="javascript">
function aa()
{
alert('An onMouseOver event');return false
//<div onmousemove="javascript:aa()">asdfasdfasdfasdf</div>
}
</script>
</head>
<body>
<div id='abc1'>asdfasdfasdfwerasdfqwer</div>
<a href="javascript:aa()">This is a link</a>
</body>
</html>
Option Explicit
Private WithEvents oWebKit As cWebKit
Public Property Get Browser() As cWebKit
Set Browser = oWebKit
End Property
Private Sub oWebKit_JSEventCallBack(EventName As String, JSONEventObj As vbRichClient5.cCollection, JSONResult As vbRichClient5.cCollection)
MsgBox EventName & vbTab & ",JSEventCallBack"
End Sub
Private Sub oWebKit_NewWindowRequest(NewWebKitInstance As vbRichClient5.cWebKit, ByVal OpenAsTab As Boolean)
Set oWebKit = NewWebKitInstance
OpenAsTab = True
End Sub
Private Sub UserControl_Initialize()
Set oWebKit = New_c.WebKit(True, "D:\Work\vbRC5BaseDlls")
oWebKit.InitWebKitDll "WebKit.dll"
oWebKit.InitializeView UserControl.hWnd
End Sub
Private Sub UserControl_Resize()
On Error Resume Next
UserControl.ScaleMode = vbPixels
oWebKit.Move 0, 0, UserControl.ScaleWidth, UserControl.ScaleHeight
End Sub
Private Sub UserControl_Terminate()
Set oWebKit = Nothing
End Sub
Option Explicit
Private Sub Command_Click()
wcMain.Browser.Navigate2 App.Path & "\DDD.html"
Dim a As IDOMDocument
'在執行這一句的時候老報錯是怎麼回事呀?
Set a = wcMain.Browser.GetElementByID("abc1")
End Sub
Private Sub Form_Resize()
On Error Resume Next
wcMain.Move wcMain.Left, wcMain.Top, Me.Width - 500, Me.Height - wcMain.Top - 600
End Sub
Private Sub Form_Unload(Cancel As Integer)
New_c.CleanupRichClientDll
End Sub
Dim a As IDOMElement
Set a = wcMain.Browser.GetElementByID("btnAdd")
'用 AddScript 加入jQuery庫以后
'這一句可以
a.setAttribute "onclick", "javascript: window.location=""http://192.168.91.24/htdocs/a.gif"";"
'這一句不行,也就是不能讀本地的圖片資源,不知道為什麼?
a.setAttribute "onclick", "javascript: window.location=""file:///c:/a.gif"";"
wcMain.Browser.Navigate2 App.Path & "\DDD.html"
Dim a As IDOMDocument
Dim b As IDOMElement
Dim c As IDOMElement
'这样可以
Set a = wcMain.Browser.Document
Set b = a.documentElement()
‘这一句就不行
Set c = a.GetElementByID("abc1")
wcMain.Browser.AddScript "function aa(){alert('An onMouseOver event');return false}"
DoEvents
wcMain.Browser.LoadHTMLString "<body><div id='abc1'>你好,我愛死你了</div><div id='abc2' onClick=""javascript:aa()"">我不好</div></body>"
Dim b As IDOMNode
Set b = wcMain.Browser.GetElementByID("abc1")
'取出id文本
MsgBox b.textContent
wcMain.Browser.NodeReplaceInnerHTML b, "他也好,我愛死你了"
'給abc1增加一個click事件
wcMain.Browser.RegisterEventCallbackOn b, "onclick", "DEF"