0
我打開一個網頁視圖頁面,頁面有評估上的WebView JavaScript值,Android的
<script type="text/javascript">
var addToBasketDisabled=false;
var iPhoneStatus="";
function GetStatus()
{
return iPhoneStatus;//Master Pagelerde tanımlı
}
var path = "http://www.yemeksepeti.com/App_Themes/Default_tr-TR/images/IPhone/";
function PreLoadDisabledButton()
{
var image = new Image();
image.src=path + "Iphone-button-ekle-pasif.png";
}
function DisableAddButton()
{
addToBasketDisabled= true;
var buttonObject = document.getElementById("ctl00_AddToBasket");
buttonObject.src = path + "Iphone-button-ekle-pasif.png";
}
function EnableAddButton()
{
addToBasketDisabled= false;
var buttonObject = document.getElementById("ctl00_AddToBasket");
buttonObject.src = path + "Iphone-button-ekle.png";
}
function OnAddButtonClick()
{
if(addToBasketDisabled)
{
return false;
}
DisableAddButton();
var validateValue= ValidateInput();
if(!validateValue)
{
EnableAddButton();
return false;
}
}
PreLoadDisabledButton();
</script>
這些JavaScript 當我按在網頁視圖按鈕我要讀的「iPhoneStatus」的價值和關閉webview屏幕並決定結果。
我在的.java類
mWebView = (WebView) findViewById(R.id.webview);
WebSettings webSettings = mWebView.getSettings();
webSettings.setSavePassword(false);
webSettings.setSaveFormData(false);
webSettings.setJavaScriptCanOpenWindowsAutomatically(true);
webSettings.setJavaScriptEnabled(true);
webSettings.setSupportZoom(false);
mWebView.setWebChromeClient(new MyWebChromeClient());
mWebView.addJavascriptInterface(new DemoJavaScriptInterface(), "demo");
mWebView.loadUrl(feedurl);
final class DemoJavaScriptInterface
{
DemoJavaScriptInterface()
{
}
public void clickOnAndroid()
{
mHandler.post(new Runnable()
{
public void run()
{
mWebView.loadUrl("javascript: GetStatus()");
}
});
}
}
final class MyWebChromeClient extends WebChromeClient
{
public void onCloseWindow(WebView window)
{
window.destroy();
}
public boolean onJsAlert(WebView view, String url, String message, JsResult result)
{
Log.i("log ", message);
result.confirm();
return true;
}
}
寫了這些代碼,但它在onJsAlert方法不會去,有沒有什麼辦法來評估的getStatus()的值
感謝