Android Question WebView calls windows.print()


In my application, we open a webview page to display document. Inside the webview have a print button which will call javascript the windows.print() funtion. Currently its only working in browser but not in a webview. Any advice?


Well-Known Member
Licensed User
You need to add the WebviewExtras library to make the conncetion between Weview content and B4A
WebView call javascript:
Sub Globals
    'These global variables will be redeclared each time the activity is created.
    'These variables can only be accessed from this module.
    Dim webview As WebView
    Dim wex As WebViewExtras
End Sub

Sub Activity_Create(FirstTime As Boolean)
    'Do not forget to load the layout file created with the visual designer. For example:
    wex.addJavascriptInterface(webview, "B4A")
    wex.addWebChromeClient(webview, "wex")
    Activity.AddView(webview, 0%x,0%y,100%x,100%y)
    Sleep(10000)   ' to give you time to look at your device
'    wex.executeJavascript( webview, "document.getElementById('omo').style.color='green';")
    wex.executeJavascript( webview, "document.getElementById('colorbutton').click();")
End Sub
HTML page:
<!DOCTYPE html>
<script type='text/javascript'>
   function changecolor() {
      var e = document.getElementById('omo');
      if ( === 'red') = 'blue';
     else = 'red';
<div id='omo' style='font-Size:xx-large; color:red; text-align:center;width:100%;height:100px;'>OMO</div>
<input type='button' id='colorbutton' value=' change color ' onclick='changecolor();'>
Upvote 0