2013-10-27 75 views
0

我想讓JavaScript被啓用,我以爲我有它的權利,但是當我在我的手機上運行它似乎不加載JavaScript。我也想知道如何加載webview外部的外部鏈接,因爲現在我有覆蓋只能加載到我的web視圖中,我該如何將它翻轉到哪裏沒有從我的網站加載外部?在webview中啓用Javascript?

我把它放在錯誤的地方嗎?

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; 
} 

} 

回答

0
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); 

設置這些屬性