addJavascriptInterface ¿À·ù(Android WebView.addJavascriptInterface not Working) |
|
|
 |
8³â Àü |
°©Àڱ⠾ȵǴ WebView.addJavascriptInterface ÀÇ ¿øÀÎÀº Á©¸®ºó MR1 ¾÷µ¥ÀÌÆ®ºÎÅÍ ÀÚ¹Ù½ºÅ©¸³Æ®¿¡ °ø°³ÇÒ ÇÔ¼ö¿¡ ´ëÇØ ÁÖ¼®(annotated)ÇØÁà¾ß Çϱ⠶§¹®À̾ú´Ù.
http://developer.android.com/reference/android/webkit/WebView.html#addJavascriptInterface(java.lang.Object, java.lang.String)
Injects the supplied Java object into this WebView. The object is injected into the JavaScript context of the main frame, using the supplied name. This allows the Java object's methods to be accessed from JavaScript. For applications targeted to API level JELLY_BEAN_MR1 and above, only public methods that are annotated with JavascriptInterface can be accessed from JavaScript. For applications targeted to API level JELLY_BEAN or below, all public methods (including the inherited ones) can be accessed, see the important security note below for implications.
¿¹½Ã
class JsObject {
//Áß¿äÇÑ ÁÖ¼®Ç¥½Ã(¾î³ëÅ×À̼Ç)
@JavascriptInterface
public String toString() { return "injectedObject"; }
}
webView.addJavascriptInterface(new JsObject(), "injectedObject");
webView.loadData("", "text/html", null);
webView.loadUrl("javascript:alert(injectedObject.toString())");
|
|
̵̧ : 337 |
̵̧
¸ñ·Ï
|
|