2011-11-08 19 views

回答

3

你可以嘗試以下操作:

mWebView.loadUrl("javascript: document.forms['myform_id'].value ='" + newValue + "'"); 

最良好的祝願, 添

+0

我將使用'document.getElementById(「inName」)'來獲取元素,並且您將需要轉義newValue中的單引號。 –

+0

你是完全正確的 - 如果你想設置一個字符串,你需要說.value ='「+ newValue +」')「); – Tim

+0

@Kevin Galligan你能告訴我如何使用這段代碼嗎?在哪裏我到達網站?因爲在我的情況下,這段代碼不工作=( – vladimir

0

另一種方式去是使用JavaScriptInterface例如:

class JsObject { 
    @JavascriptInterface 
    public String toString() { return "injectedObject"; } 
} 
webView.addJavascriptInterface(new JsObject(), "injectedObject"); 
webView.loadData("", "text/html", null); 
webView.loadUrl("javascript:alert(injectedObject.toString())"); 
+0

提供示例總是比發佈內容更好鏈接可能已經死了 –