Note that there are some explanatory texts on larger screens.

plurals
  1. POCalling javascript functions in a webview from activity class
    primarykey
    data
    text
    <p>Edit: This snipped worked in the end. I had been trying this before but was actually experiencing a scoping issue with my javascript. I had appBack() defined in document.onready. Simply re-scoping that function to *window.*appBack = function(). Done the business. Hope this helps someone.</p> <pre><code>public boolean onKeyDown(int keyCode, KeyEvent event) { if (keyCode == KeyEvent.KEYCODE_BACK) { WebView.loadUrl("javascript:appBack()"); return true; } return super.onKeyDown(keyCode, event); } </code></pre> <hr> <p>Within a webview application the back navigation is handled with a custom JS function <em>appBack()</em> I've been trying to figure out a way to intercept the android physical back button and call that javascript function instead. Here is my activity file. Its very basic, sets up a webview and listens for the back button click. Currently when the user clicks this physical back button it runs mWebView.goBack(). Which is where I would like to perform javascript:appBack()</p> <pre><code>package com.stgeorgeplc.app; import android.app.Activity; import android.os.Bundle; import android.view.KeyEvent; import android.webkit.WebView; public class StGeorgePLCliteActivity extends Activity { /** Called when the activity is first created. */ WebView mWebView; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); mWebView = (WebView) findViewById(R.id.webview); mWebView.getSettings().setJavaScriptEnabled(true); mWebView.getSettings().setBuiltInZoomControls(true); mWebView.loadUrl("file:///android_asset/www/index.html"); } public boolean onKeyDown(int keyCode, KeyEvent event) { if (keyCode == KeyEvent.KEYCODE_BACK) { mWebView.goBack(); return true; } return super.onKeyDown(keyCode, event); } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload