2014-03-28 39 views
0

我試圖在Android上工作的JavaScript此頁:JavaScript的網頁視圖不使用JavaScript啓用

http://test.swiss-impulse.com/scratch_card_game/index.html

但是我有一個關於瀏覽器的問題。

webView1.setWebChromeClient(mClient); 

webView1.setDownloadListener(new DownloadListener() { 

     @Override 
     public void onDownloadStart(String url, String userAgent, String contentDisposition, String mimetype, long contentLength) { 
      Uri uri = Uri.parse(url); 
      Intent intent = new Intent(Intent.ACTION_VIEW, uri); 
      startActivity(intent); 
     } 
    }); 

webView1.addJavascriptInterface(new JavaScriptInterfaceForTitle(this, mPasswordStrength, webView1), "HtmlViewer"); 

webView1.setWebViewClient(new WebViewClient() { 
     @Override 
     public void onPageStarted(WebView view, String url, Bitmap favicon) { 
      String cookie = CookieManager.getInstance().getCookie(url); 
      if (url.equals(getContentUrl() + "addcomment")) { 
       webView1.stopLoading(); 
       Intent addcommentIntent = new Intent(mContext, AddCommentActivity.class); 
       addcommentIntent.putExtra("url", previousUrl); 
       startActivity(addcommentIntent); 
      } else { 
       previousUrl = url; 
       ((BaseActivity) mContext).showLoadingDialog(); 
       if (!urlStackList.contains(url)) { 
        urlStackList.add(url); 
       } 
       super.onPageStarted(view, url, favicon); 
      } 
     } 

     @Override 
     public void onPageFinished(WebView view, String url) { 
      ((BaseActivity) mContext).hideLoadingDialog(); 
      if (url.contains("content/shows/") || url.contains("content/tips/")) { 
       counter = 0; 
       view.loadUrl("javascript:window.HtmlViewer.showHTML(document.getElementById('" + mContext.getString(R.string.title_name) + "').innerHTML);"); 
       view.loadUrl("javascript:window.HtmlViewer.showHTML(document.getElementById('name_en').innerHTML);"); 
       view.loadUrl("javascript:window.HtmlViewer.showHTML(document.getElementById('name_zh').innerHTML);"); 
      } else { 
       mStateBar.setShowTitle(mContext.getString(R.string.tv_drama)); 
      } 
      super.onPageFinished(view, url); 
     } 

    }); 
webview1.setWebChromeClient(mClient); 
webView1.getSettings().setJavaScriptEnabled(true); 
webView1.getSettings().setPluginState(PluginState.ON); 
webView1.getSettings().setPluginsEnabled(true); 
webView1.getSettings().setAppCacheMaxSize(httpCacheSize); 
webView1.getSettings().setSupportZoom(false); 
webView1.getSettings().setBuiltInZoomControls(false); 
webView1.getSettings().setJavaScriptCanOpenWindowsAutomatically(true); 

我失去了一些參數,使在Android的WebView這項工作:

這是爲網頁視圖設置的參數?我檢查了Chrome瀏覽器,它沒有問題,所以我肯定我錯過了一些東西,找不到什麼。

編輯:

class MyChromeClient extends WebChromeClient { 

    @Override 
    public void onShowCustomView(View view, CustomViewCallback callback) { 
     mCustomViewCallback = callback; 
     mTargetView.addView(view); 
     mCustomView = view; 
     mContentView.setVisibility(View.GONE); 
     mTargetView.setVisibility(View.VISIBLE); 
     mTargetView.bringToFront(); 
    } 

    @Override 
    public void onHideCustomView() { 
     if (mCustomView == null) 
      return; 

     mCustomView.setVisibility(View.GONE); 
     mTargetView.removeView(mCustomView); 
     mCustomView = null; 
     mTargetView.setVisibility(View.GONE); 
     mCustomViewCallback.onCustomViewHidden(); 
     mContentView.setVisibility(View.VISIBLE); 
    } 

    // For Android 3.0+ 
    public void openFileChooser(ValueCallback<Uri> uploadMsg, String acceptType) { 
     mUploadMessage = uploadMsg; 
     Intent i = new Intent(Intent.ACTION_GET_CONTENT); 
     i.addCategory(Intent.CATEGORY_OPENABLE); 
     i.setType("image/*"); 
     TvDramaActivity.this.startActivityForResult(Intent.createChooser(i, "Chooser"), 100); 
    } 

    // For Android < 3.0 
    public void openFileChooser(ValueCallback<Uri> uploadMsg) { 
     openFileChooser(uploadMsg, ""); 
    } 

    // For Android > 4.1 
    public void openFileChooser(ValueCallback<Uri> uploadMsg, String acceptType, String capture) { 
     openFileChooser(uploadMsg, ""); 
    } 

    @Override 
    public void onProgressChanged(WebView view, int newProgress) { 
    } 
} 

public boolean inCustomView() { 
    return (mCustomView != null); 
} 

public void hideCustomView() { 
    mClient.onHideCustomView(); 
} 
+1

LogCat中是否存在任何錯誤或警告 – peshkira

+0

添加webview1.setWebChromeClient(new WebChromeClient()); –

+0

沒有錯誤或警告 – Tazz

回答

1

這個工作對我來說:

在你的WebView活動類:

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

    webView1 = (WebView) findViewById(R.id.web); 

    webView1.setWebChromeClient(new WebChromeClient()); 
    webView1.getSettings().setJavaScriptEnabled(true); 
    webView1.getSettings().setPluginState(PluginState.ON); 

    webView1.getSettings().setSupportZoom(false); 
    webView1.getSettings().setBuiltInZoomControls(false); 
    webView1.getSettings().setJavaScriptCanOpenWindowsAutomatically(true); 

    webView1.loadUrl("http://test.swiss-impulse.com/scratch_card_game/index.html"); 
    } 

您的佈局文件:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:tools="http://schemas.android.com/tools" 
android:id="@+id/container" 
android:layout_width="match_parent" 
android:layout_height="match_parent"> 

<WebView 
    android:id="@+id/web" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent"/> 

</LinearLayout> 

不要忘記在清單文件中添加<uses-permission android:name="android.permission.INTERNET"/>

希望這有助於。謝謝。

+0

頁面是否劃痕?我的意思是,如果你劃過藍色區域,是否有圖片? – Tazz

+0

是的..我測試了它,它工作得很好。 –

+0

你也可以從你的頭上檢查一下。 –