B4J Question How to display the contextmenu in a web page in webview?

yshzsl

Member
I used webview in B4J to load the webpage index.html, which embedded the editor ueditor. ueditor configured the context menu using JavaScript.

When index.html is loaded in the browser, the context menu can be displayed and run normally,but it cannot be displayed in webview. WebView only displays its default context menu (only cut, copy, paste)
How can I display the context menu of UEditor in a webview?
 

yshzsl

Member
Thank you for your attention and suggestions, Erel.
I tried this method, and the default context menu for webview is no longer displayed, but the right-click menu for the webpage is also not showing.
 
Upvote 0

yshzsl

Member
The problem has been resolved through two main steps:
1. According to Mr. Erel's guidance, disable the default context menu of webview after loading webpage.
Dim jo As JavaObject=WebView1
jo.RunMethod("setContextMenuEnabled",Array(False))

2. Add a right-click event to the webview and pass the mouse coordinates to UEditor.
The code is as follows:

B4X:
Private Sub WebView1_MouseClicked (EventData As MouseEvent)
    If EventData.SecondaryButtonPressed Then   
        Dim x As Int = EventData.X
        Dim y As Int = EventData.Y
        Dim js As String = $"
            editor.fireEvent('contextmenu', {
            clientX: ${x},
            clientY: ${y},
            target: document.getElementById('editor')
            });
        "$
        ExecuteJavaScript(WebView1,js)           
    End If
End Sub
 
Upvote 0

yshzsl

Member
The issue with the default context menu for webview has been resolved, but a new problem regarding webview has been discovered:
Namely: Support issue for Chinese in webview:
1. For the bold and italic styles of fonts set with inline style on web pages, only English characters are valid and Chinese characters are invalid;
2. For fonts set with inline style in web pages, it is not valid for Chinese fonts SimSun, SimKai, and Fangsong_GB2312, but it is valid for Microsoft YaHei and SimHei (bold and italic styles are still invalid).(These fonts have been installed normally on the Windows system).
3. The same webpage content, the above settings are valid in browser.
4. Even with a simple HTML webpage that does not include UEditor.

I don't know if the above problem is caused by webview or B4J. Have you encountered it before and do you have any good solutions?
Please help me.
 
Upvote 0
Top