Merge "WebView: clarify docs for addJavascriptInterface" into oc-mr1-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
bc99692f02
@@ -1926,13 +1926,14 @@ public class WebView extends AbsoluteLayout
|
|||||||
* For applications targeted to API level {@link android.os.Build.VERSION_CODES#JELLY_BEAN} or below,
|
* For applications targeted to API level {@link android.os.Build.VERSION_CODES#JELLY_BEAN} or below,
|
||||||
* all public methods (including the inherited ones) can be accessed, see the
|
* all public methods (including the inherited ones) can be accessed, see the
|
||||||
* important security note below for implications.
|
* important security note below for implications.
|
||||||
* <p> Note that injected objects will not
|
* <p> Note that injected objects will not appear in JavaScript until the page is next
|
||||||
* appear in JavaScript until the page is next (re)loaded. For example:
|
* (re)loaded. JavaScript should be enabled before injecting the object. For example:
|
||||||
* <pre>
|
* <pre>
|
||||||
* class JsObject {
|
* class JsObject {
|
||||||
* {@literal @}JavascriptInterface
|
* {@literal @}JavascriptInterface
|
||||||
* public String toString() { return "injectedObject"; }
|
* public String toString() { return "injectedObject"; }
|
||||||
* }
|
* }
|
||||||
|
* webview.getSettings().setJavaScriptEnabled(true);
|
||||||
* webView.addJavascriptInterface(new JsObject(), "injectedObject");
|
* webView.addJavascriptInterface(new JsObject(), "injectedObject");
|
||||||
* webView.loadData("<!DOCTYPE html><title></title>", "text/html", null);
|
* webView.loadData("<!DOCTYPE html><title></title>", "text/html", null);
|
||||||
* webView.loadUrl("javascript:alert(injectedObject.toString())");</pre>
|
* webView.loadUrl("javascript:alert(injectedObject.toString())");</pre>
|
||||||
|
|||||||
Reference in New Issue
Block a user