Calling javascript functions from webview Android -
i have webview , loaded html file.
now want call javascript function datainput() webview.
here code.but console returns
e/web console(435): uncaught referenceerror: datainput not defined:1 does know why? thanks!
webview engine = (webview) (findviewbyid(r.id.webview1)); engine.setwebviewclient(new webviewclient()); engine.setwebchromeclient(new webchromeclient() { public boolean onconsolemessage(consolemessage cm) { log.d("myapplication", cm.message() + " -- line " + cm.linenumber() + " of " + cm.sourceid() ); return true; } }); engine.getsettings().setjavascriptenabled(true); engine.getsettings().setpluginsenabled(true); engine.loadurl("file:///" + path); engine.loadurl("javascript:datainput()"); my html files includes following code:
<script type="text/javascript"> function datainput( ) { $( "video" ).each( function(e){this.play();} ); $( "video" ).bind( "ended", function(e){this.play();}); } </script> further edit:::::
i added button , calls js upon onclick , (kinda) worked... i.e.
public void onclick(view arg0) { engine.loadurl("javascript:datainput()"); } how come???? really want know why.....
p.s. said (kinda) work because video did autoplay (due $( "video" ).each( function(e){this.play();} );) not loop ($( "video" ).bind( "ended", function(e){this.play();}); <<< not working)
change javascript this
<script type="text/javascript" src="location_of_your_jquery_file" /> <script type="text/javascript"> $(document).ready(function () { $.fn.gotofunc = function () { $("video").each(function (e) { this.play(); }); $("video").bind("ended", function (e) { this.play(); }); }; function datainput() { $.fn.gotofunc(); } }); </script>
Comments
Post a Comment