Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/475.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
我是android webview的新手,使用JavaScript_Javascript_Android_Jquery_Android Webview - Fatal编程技术网

我是android webview的新手,使用JavaScript

我是android webview的新手,使用JavaScript,javascript,android,jquery,android-webview,Javascript,Android,Jquery,Android Webview,我正在尝试让我的android应用程序使用JavaScript。我已经启用了JavaScript。我不知道为什么这不起作用,我所做的所有研究都认为应该这样做。非常感谢您的帮助 这是我的Java代码 protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); getWindow().requestFeature(Window.FEATURE_PROGRESS

我正在尝试让我的android应用程序使用JavaScript。我已经启用了JavaScript。我不知道为什么这不起作用,我所做的所有研究都认为应该这样做。非常感谢您的帮助

这是我的Java代码

    protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    getWindow().requestFeature(Window.FEATURE_PROGRESS);
    getWindow().setFeatureInt(Window.FEATURE_PROGRESS, Window.PROGRESS_VISIBILITY_ON);
    WebView webview = new WebView(this);
    setContentView(webview);
    setProgressBarVisibility(true); 

    webview.getSettings().setJavaScriptEnabled(true);
    webview.setScrollBarStyle(View.SCROLLBARS_INSIDE_OVERLAY);


    final Activity activity = this;
}



@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    if (keyCode == KeyEvent.KEYCODE_BACK) {

        webview.goBack();

        return true;
    }
    return super.onKeyDown(keyCode, event);
}


@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.main, menu);


    webview = new WebView(this);      
    webview.setWebViewClient(new WebViewClient() {  
        @Override  
        public boolean shouldOverrideUrlLoading(WebView view, String url)  
        {  
          view.loadUrl(url);  
          return true;  
        }  
      });                 
    setContentView(webview);      
    webview.loadUrl("http://www.example.com/droid/mobile_index.html");
    return true;}
下面是我试图与之交互的JavaScript

   <script type="text/javascript">
   function reply_click(clicked_name)
   {
   var clicked_name;
document.location="http://www.example.com/droid/updatescore.php?location=" +    clicked_name;

     }
     </script>

功能回复点击(点击名称)
{
var和U名称;
文档位置=”http://www.example.com/droid/updatescore.php?location=“+你的名字;
}

我有一个动态创建的php表,其中的单元格并不总是具有相同的名称。我使用JavaScript和DOM来获取变量,并将其作为URL中的变量传递到新网页。它在我的电脑浏览器上工作得很好,但在我的手机上却不行。我已经启用了JavaScript,但是它不起作用。我做错了什么?谢谢

我不知道你用onCreateOptions菜单假装什么。这就是应该在onCreate中的代码

这样,您应该在onCreate方法中设置WebViewClient

然后,您的代码应该如下所示:

private static WebView webView;

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    getWindow().requestFeature(Window.FEATURE_PROGRESS);
    getWindow().setFeatureInt(Window.FEATURE_PROGRESS, Window.PROGRESS_VISIBILITY_ON);
    webview = new WebView(this);
    webview.setWebViewClient(new WebViewClient() {  
        @Override  
        public boolean shouldOverrideUrlLoading(WebView view, String url)  
        {  
              return false;  
        }  
      }); 
    setProgressBarVisibility(true); 

    webview.getSettings().setJavaScriptEnabled(true);
    webview.setScrollBarStyle(View.SCROLLBARS_INSIDE_OVERLAY);

setContentView(webview);

    final Activity activity = this;
}



@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    if (keyCode == KeyEvent.KEYCODE_BACK) {

        webview.goBack();

        return true;
    }
    return super.onKeyDown(keyCode, event);
}


@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.main, menu);

    webview.loadUrl("http://www.example.com/droid/mobile_index.html");
    return true;
}

试试看

我找到了一个回答我问题的教程,希望它能有所帮助

谢谢你的评论Regys788880,但是这似乎没有帮助。。。还有其他想法吗。我已经为此工作了3天,但都没有用。。。