<HTML><Head> <Metacontent= "text/html; charset=utf-8"http-equiv= "Content-type"> <title>JS call Java</title></Head><Body><P> <DivID= "Show"></Div></P><P><inputtype= "button"ID= "Enter3"value= "Payinterface"onclick= "payinterface ();"/></P></Body><Script> functionSetupwebviewjavascriptbridge (callback) {if(window. Webviewjavascriptbridge) {callback (Webviewjavascriptbridge)}Else{Document.addeventlistener ('Webviewjavascriptbridgeready' , function() {Callback (Webviewjavascriptbridge)},false ); } if(window. Wvjbcallbacks) {returnwindow. Wvjbcallbacks.push (callback); } window. Wvjbcallbacks=[callback]; varWvjbiframe=Document.createelement ('iframe'); WVJBIframe.style.display= 'None'; WVJBIFRAME.SRC= 'wvjbscheme://__bridge_loaded__'; Document.documentElement.appendChild (Wvjbiframe); SetTimeout (function() {Document.documentElement.removeChild (Wvjbiframe)},0) } //adding a native tune-up JS method in the Change functionSetupwebviewjavascriptbridge (function(bridge) {//registering a native Tune-up method //parameter 1:BUTTONJS registered flag for native use, to be unified with native //The parameter 2:data is the data passed to JS by the native //The parameter 3:responsecallback is the callback of JS, which can be used to transmit data to the nativeBridge.registerhandler ("Getuserinfos",function(data,responsecallback) {document.getElementById ("Show"). InnerHTML= "Buuton JS" +data; Responsecallback ("Button JS Callback"); }); document.getElementById ('Enter3'). onclick= function(e) {varData= "Hello" //parameter 1:pay registered flag for native use, to be unified with native //parameter 2: A parameter that is passed to the native when it is tuned //Parameter 3: Data returned by native invocation callbackBridge.callhandler ('GETBLOGNAMEFROMOBJC', data,function(RESP) {document.getElementById ("Show"). InnerHTML= "Payinterface" +resp; } ); } })</Script></HTML>
function Connectwebviewjavascriptbridge (callback) {if (window. Webviewjavascriptbridge) {callback (Webviewjavascriptbridge)} else {Document.addeventlistener (' Webviewjavascriptbridgeready ', function () {callback (Webviewjavascriptbridge)}, False); } (function (bridge) {Bridge.registerhandler (' JS Echo ', function (data,}connectwebviewjavascriptbridge Responsecallback) {console.log ("JS Echo called with:", data) Responsecallback (data)}) Bridge.callhandler (' oliveness ', {}, Function Responsecallback (responsedata) {})})
jsbrage--and app Interaction