2023-07-14, 11:00:59
Hi,
Yes, of course you can.
Taking the example from w3schools that you attached I went to the VB6 browser demo form and added a new button to the form called "AutoTranslateButton" and put the following code in the OnClick event.
and that worked for me.
Navigating to the antwise.com website, then clicking the "Translate" button nicely inserted the google translate feature into the page.
Hope this helps,
--
Wil
Yes, of course you can.
Taking the example from w3schools that you attached I went to the VB6 browser demo form and added a new button to the form called "AutoTranslateButton" and put the following code in the OnClick event.
Code:
Private Sub AutoTranslateButton_Click()
Dim sEle As String
Dim jScript As String
sEle = "const tempDiv = document.createElement('div');" & vbCrLf
sEle = sEle & "tempDiv.id = 'google_translate_element'" & vbCrLf
sEle = sEle & "document.body.insertAdjacentElement('afterbegin',tempDiv);" & vbCrLf
EdgeWebBrowser.ExecuteScript (sEle)
jScript = "" & vbCrLf
jScript = jScript & "function googleTranslateElementInit() {" & vbCrLf
jScript = jScript & "new google.translate.TranslateElement({pageLanguage: 'en'}, 'google_translate_element');" & vbCrLf
jScript = jScript & "}" & vbCrLf
EdgeWebBrowser.ExecuteScript (jScript)
sEle = "const tempScript = document.createElement('script');" & vbCrLf
sEle = sEle & "tempScript.type = 'text/javascript'" & vbCrLf
sEle = sEle & "tempScript.src = '//translate.google.com/translate_a/element.js?cb=googleTranslateElementInit'" & vbCrLf
sEle = sEle & "document.body.insertAdjacentElement('beforeend',tempScript);" & vbCrLf
EdgeWebBrowser.ExecuteScript (sEle)
End Sub
and that worked for me.
Navigating to the antwise.com website, then clicking the "Translate" button nicely inserted the google translate feature into the page.
Hope this helps,
--
Wil