結果在:
base/core/res/res/values-zh-rTW/strings.xml:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<string name="js_dialog_title" msgid="8143918455087008109">"「<xliff:g id="TITLE">%s</xliff:g>」的網頁指出:"</string> |
使用者是:
base/core/java/android/webkit/CallbackProxy.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private String getJsDialogTitle(String url) { | |
String title = url; | |
if (URLUtil.isDataUrl(url)) { | |
// For data: urls, we just display 'JavaScript' similar to Safari. | |
title = mContext.getString(R.string.js_dialog_title_default); | |
} else { | |
try { | |
URL aUrl = new URL(url); | |
// For example: "The page at 'http://www.mit.edu' says:" | |
title = mContext.getString(R.string.js_dialog_title, | |
aUrl.getProtocol() + "://" + aUrl.getHost()); | |
} catch (MalformedURLException ex) { | |
// do nothing. just use the url as the title | |
} | |
} | |
return title; | |
} |
猜是 confirm dialog:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
case JS_CONFIRM: | |
if (mWebChromeClient != null) { | |
final JsResult res = (JsResult) msg.obj; | |
String message = msg.getData().getString("message"); | |
String url = msg.getData().getString("url"); | |
if (!mWebChromeClient.onJsConfirm(mWebView, url, message, | |
res)) { | |
new AlertDialog.Builder(mContext) | |
.setTitle(getJsDialogTitle(url)) | |
.setMessage(message) | |
.setPositiveButton(R.string.ok, | |
new DialogInterface.OnClickListener() { | |
public void onClick( | |
DialogInterface dialog, | |
int which) { | |
res.confirm(); | |
}}) | |
.setNegativeButton(R.string.cancel, | |
new DialogInterface.OnClickListener() { | |
public void onClick( | |
DialogInterface dialog, | |
int which) { | |
res.cancel(); | |
}}) | |
.setOnCancelListener( | |
new DialogInterface.OnCancelListener() { | |
public void onCancel( | |
DialogInterface dialog) { | |
res.cancel(); | |
} | |
}) | |
.show(); | |
} | |
// Tell the JsResult that it is ready for client | |
// interaction. | |
res.setReady(); | |
} | |
break; |
所以是在處理 javascript 的 alert。
其中有 mWebChromeClient 不是 null 時,才會處理。
在 browser/Tab.java 中,有使用 setWebChromeClient..
所以... setWebViewClient( ) 和 setWebChromeClient( ) 的不同處是...?
ref: http://stackoverflow.com/questions/2835556/whats-the-difference-between-setwebviewclient-vs-setwebchromeclient
setWebChromeClient( ) 會處理 JS Alert。
拿 http://www.mkyong.com/tutorials/android-tutorial/ 的 WebView Example code 來測試這個 javascript alert 頁面。
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.mkyong.android; | |
import android.app.Activity; | |
import android.os.Bundle; | |
import android.webkit.WebChromeClient; | |
import android.webkit.WebView; | |
import android.webkit.WebViewClient; | |
public class WebViewActivity extends Activity { | |
private WebView webView; | |
public void onCreate(Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
setContentView(R.layout.webview); | |
webView = (WebView) findViewById(R.id.webView1); | |
webView.getSettings().setJavaScriptEnabled(true); | |
webView.setWebViewClient(new WebViewClient()); | |
webView.setWebChromeClient(new WebChromeClient()); | |
webView.loadUrl("http://lexandera.com/files/jsexamples/alert.html"); | |
} | |
} |
試著拿掉 setWebChromeClient( ) 這行,執行時,就不會出現 dialog
沒有留言:
張貼留言