Note that there are some explanatory texts on larger screens.

plurals
  1. POJavaScript does not work in webView
    primarykey
    data
    text
    <p>I have some problem whith WebView. Javascript doesn't work. On android 2.2 whith loadUrl(), it works well. But when I run it on android 4 using <strong>loadDataWithBaseURL</strong>, it doesn't work. What am I doing wrong?</p> <p><strong>MainActivity</strong> </p> <pre><code> import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import android.os.Bundle; import android.app.Activity; import android.content.Context; import android.view.Menu; import android.webkit.WebView; import android.widget.Toast; public class MainActivity extends Activity { String webData = null; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); webData = getHtmlFromAsset(); WebView webView = (WebView) findViewById(R.id.webView1); webView.getSettings().setJavaScriptEnabled(true); //webView.loadUrl("file:///android_asset/index.html"); //webView.loadData(webData, "text/html", "UTF-8"); webView.addJavascriptInterface(new JavaScriptIntefeise(this), "Android"); webView.loadDataWithBaseURL(getAssets().toString(), webData, "text/html", "UTF-8", null); } @Override public boolean onCreateOptionsMenu(Menu menu) { getMenuInflater().inflate(R.menu.main, menu); return true; } private String getHtmlFromAsset() { InputStream is; StringBuilder builder = new StringBuilder(); String htmlString = null; try { is = getAssets().open(getString(R.string.index)); if (is != null) { BufferedReader reader = new BufferedReader(new InputStreamReader(is)); String line; while ((line = reader.readLine()) != null) { builder.append(line); } htmlString = builder.toString(); } } catch (IOException e) { e.printStackTrace(); } return htmlString; } class JavaScriptIntefeise { Context ctx; public JavaScriptIntefeise(Context ctx) { this.ctx = ctx; } public void showToast() { Toast.makeText(ctx, "ping", 3000).show(); } } } </code></pre> <p>simple sgnalR client <strong>index.html</strong></p> <pre><code>&lt;html&gt; &lt;head&gt; &lt;title&gt;Insert title here&lt;/title&gt; &lt;script type="text/javascript" src="json2.js" &gt;&lt;/script&gt; &lt;script type="text/javascript" src="jquery-1.9.0.js" &gt;&lt;/script&gt; &lt;script type="text/javascript" src="jquery.signalR.js" &gt;&lt;/script&gt; &lt;script type="text/javascript" src="http://192.168.0.100/FloorSpy.DuplexService/signalr/hubs/"&gt;&lt;/script&gt; &lt;/head&gt; &lt;body&gt; &lt;span&gt;signalR&lt;/span&gt; &lt;script type="text/javascript"&gt; if(!window.jQuery) document.body.style.backgroundColor = '#ff8000';; $.connection.hub.url = "http://192.168.0.100/FloorSpy.DuplexService/signalr"; var connection = $.connection.notif; connection.client.pong = function(data) { Android.showToast(); }; $.connection.hub.start() .done(function() { // Android.showToast(); }) .fail(function(data) { //Android.showToast(); }); &lt;/script&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <p>I think the error in connecting libraries. <strong>Thanks for advice!</strong> </p>
    singulars
    1. This table or related slice is empty.
    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.
    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