Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
236 views
in Technique[技术] by (71.8m points)

android - Enabling Javascript in webview?

I am trying to get javascript to be enable, i thought i had it right but when i run it on my phone it seems to not load up the javascript. I also am wondering how i can load external links outside the webview, because right now i have the override to only load in my webview, how do i go about flipping it to where anything that isnt from my site to load externally?

Do i have it in the wrong place?

package com.webapp.area956;

import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.webkit.WebView;
import android.webkit.WebViewClient;

public class MainActivity extends Activity {





@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    WebViewClient yourWebClient = new WebViewClient()

        {
           // Override page so it's load on my view only
           @Override
           public boolean shouldOverrideUrlLoading(WebView  view, String  url)
           {
            // This line we let me load only pages inside Firstdroid Webpage
            if ( url.contains("area956") == true )
               // Load new URL Don't override URL Link
               return false;

            // Return true to override url loading (In this case do nothing).
            return true;
           }
       };

    String url = "http://www.area956.com";
    WebView view = (WebView) this.findViewById(R.id.webView1);
    view.setWebViewClient(yourWebClient);

    view.getSettings().setJavaScriptEnabled(true);

    view.loadUrl(url);

}

@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);
    return true;
}

}
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
   WebView view = (WebView) findViewById(R.id.webview1);
 view = (WebView) findViewById(R.id.webview);
  view .setWebChromeClient(new InredisChromeClient(this));
  view .setWebViewClient(new InredisWebViewClient(this));
  view .clearCache(true);
  view .clearHistory();
  view .getSettings().setJavaScriptEnabled(true);
 view .getSettings().setJavaScriptCanOpenWindowsAutomatically(true);

set these properties


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...