admin管理员组文章数量:1123107
I am trying to figure out how to capture the data passed from this JavaScript event listener...
I am opening the webpage in an edge browser control inside of my access database.
I do have the references for Microsoft HTML object Library and Microsoft Internet Controls as well as XML and scripting runtime.
Thanks in advance for your assistance!
<script>
window.addEventListener("array-event", function arrayEvent(arrayEvent) {
const {
tagName,
event,
metadata = {},
} = arrayEvent.detail;
console.log("component: " + tagName + "; user action: " + event);
if (metadata){console.log(metadata);
}
});
</script>
I haven't really tried too much as I am new to the Java side of this and am not really sure how to capture the data...
I am trying to figure out how to capture the data passed from this JavaScript event listener...
I am opening the webpage in an edge browser control inside of my access database.
I do have the references for Microsoft HTML object Library and Microsoft Internet Controls as well as XML and scripting runtime.
Thanks in advance for your assistance!
<script>
window.addEventListener("array-event", function arrayEvent(arrayEvent) {
const {
tagName,
event,
metadata = {},
} = arrayEvent.detail;
console.log("component: " + tagName + "; user action: " + event);
if (metadata){console.log(metadata);
}
});
</script>
I haven't really tried too much as I am new to the Java side of this and am not really sure how to capture the data...
Share Improve this question edited 4 hours ago BigBen 50k7 gold badges27 silver badges44 bronze badges asked 4 hours ago Mark CarlyleMark Carlyle 11 bronze badge New contributor Mark Carlyle is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct. 6- 1 I don't know much about what happened to the older "microsoft web browser" control with the transition to Edge - are you sure it's not an older IE window? – Tim Williams Commented 4 hours ago
- And what VBA have you tried? Following link shows code for IE - perhaps can be adapted for Edge stackoverflow.com/questions/49078724/…. – June7 Commented 4 hours ago
- I'm 100% sure I'm using the new edge browser embedded in a form... it is labeled EdgeBrowser39. – Mark Carlyle Commented 2 hours ago
- Ok I don’t have Access so I was doing this in Excel – Tim Williams Commented 2 hours ago
- I really don't know what VBA to try to request the data stored in the java event handler or if I should use the javascript version stored in the html or if I should run the script from vba using the execute scrript command... or if I should not use the java event handler at all and build one in VBA since I need the data in VBA... sorry If I don't have a ton of info, but I'm new to this part and if I can figure out what direction I should be going, I can likely find the code or learn it... – Mark Carlyle Commented 2 hours ago
1 Answer
Reset to default 0Here's a super-basic example of how to capture events from a web browser control.
I'm using a textbox as the event source, but you could just as easily use a hidden input element. If you want to pass structured data back and forth then you can use JSON. Note you can also pass from your VBA to the HTML page using a similar approach.
It's a bit basic compared to your window.addEventListener
mechanism, but I've found it works fine in practise.
References:
- Microsoft HTML Object Library
- Microsoft Internet Controls
In a new class module clsEvt
:
Public WithEvents el As MSHTML.HTMLInputElement
Private Function el_onchange() As Boolean
Debug.Print "changed!", el.Value
End Function
In a userform:
Dim hndlr As clsEvt
Private Sub UserForm_Activate()
Dim t, doc
WebBrowser1.Navigate "about:blank" 'load a blank page
WaitFor 2
Set doc = WebBrowser1.Document
doc.Open "html" 'write some HTML (just using a text input element for this example)
doc.write "<input type='text' size='10' id='evtInput'>"
doc.Close
Set doc = WebBrowser1.Document 'reference the new content
Set hndlr = New clsEvt 'an instance of the handler
Set hndlr.el = doc.getelementbyid("evtInput") 'set the element to monitor
End Sub
'wait for some seconds to pass
Private Sub WaitFor(sec As Long)
Dim t
t = Timer
Do
DoEvents
Loop While Timer - t < sec
End Sub
本文标签:
版权声明:本文标题:vba - How to capture variable data in Edge Browser with Access 365 from javascript event listener - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736547946a1944473.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论