如何在android系统调用多个Java脚本函数更以时间来加载web视图? [英] How to call more than one java script function at a time in android to load the webview?

查看:229
本文介绍了如何在android系统调用多个Java脚本函数更以时间来加载web视图?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个简单的Java脚本file.below是我的样本的js code

i have a simple java script file.below is my sample js code

自动播放功能(VIDEOID,ST,EN){
            player.loadVideoById({'VIDEOID':VIDEOID,'startSeconds':ST,'endSeconds':恩,'suggestedQuality':'小'});
            player.playVideo();
        }

function autoplay(videoId, st, en) { player.loadVideoById({ 'videoId': videoId, 'startSeconds': st, 'endSeconds': en, 'suggestedQuality': 'small' }); player.playVideo(); }

    function getState(){
      alert(player.getPlayerState());
        return player.getPlayerState();
    }

    function CallTweak()
    {
      alert(player.getPlayerState());
      document.getElementById("mytext").innerHTML = player.getPlayerState();
      var data=player.getPlayerState();
       AndroidFunction.showToast(data);
      alert('second alert');
    }

我调用一个函数,它工作正常,但我试图调用,例如自动播放()和CallTweak()不叫这些方法两种功能。
下面是样本code调用函数

i calling one function it works fine but i am trying to call two functions for example autoplay() and CallTweak() those methods are not called. below is sample code for calling the functions

web_view.loadUrl(JavaScript的:CallTweak());
web_view.loadUrl(JavaScript的:自动播放());

web_view.loadUrl("javascript:CallTweak()"); web_view.loadUrl("javascript:autoplay()");

如何在同一时间在一个单一的按一下按钮在Android中调用多个函数?先谢谢了。

How to call more than one function at a time in a single button click in android?Thanks in advance.

推荐答案

取两种方法之一

无论哪种,在你的JavaScript code,确定了第三函数,它们调用其他两个

Either, in your javascript code, define a third function which calls the other two

function callBothFunctions(){
    CallTweak();
    autoplay();
}

然后再调用第三个功能

and then call that third function

web_view.loadUrl("javascript:callBothFunctions()");

,另一种方法是使用像

Or, the other approach is to use an anonymous self-executing function like

 string javascriptFunctionCall = 
                      "javascript:"
                      + "(function(){"
                          + "CallTweak();"
                          + "autoplay();"
                      +"})()";

 web_view.loadUrl(javascriptFunctionCall);

这篇关于如何在android系统调用多个Java脚本函数更以时间来加载web视图?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆