1.我想问下在webview打开网页时能够和网页中的js互调吗?(不是本地的HTML)。我看了很多文章都是说的本地的HTML的,还说有个assets文件夹,难道不能在打开远端网页的时候来相互调用吗?
2.还有我想问下webview在打开网页的时候如何获得asp.net的cookie或者session或者页面的隐藏域值啊?
3.还有就是我的项目中有个TabHost,我想让它最开始隐藏,登录成功后显示,请问怎样实现呢?
在线等,有回复马上结贴。谢谢各位了。
2.还有我想问下webview在打开网页的时候如何获得asp.net的cookie或者session或者页面的隐藏域值啊?
3.还有就是我的项目中有个TabHost,我想让它最开始隐藏,登录成功后显示,请问怎样实现呢?
在线等,有回复马上结贴。谢谢各位了。
<form ...>
<input type='hidden' name='test'>
...
</form>
<script ....>
alert(document.getElementsByName('test'));
</script>
好了. 这样隐藏变量就传递给java程序了.在java中的onJsAlert中,就可以去的他的值 .ok?可以参考这个例子.package com.google.android.webviewdemo;import android.app.Activity;
import android.os.Bundle;
import android.os.Handler;
import android.util.Log;
import android.webkit.JsResult;
import android.webkit.WebChromeClient;
import android.webkit.WebSettings;
import android.webkit.WebView;/**
* Demonstrates how to embed a WebView in your activity. Also demonstrates how
* to have javascript in the WebView call into the activity, and how the activity
* can invoke javascript.
* <p>
* In this example, clicking on the android in the WebView will result in a call into
* the activities code in {@link DemoJavaScriptInterface#clickOnAndroid()}. This code
* will turn around and invoke javascript using the {@link WebView#loadUrl(String)}
* method.
* <p>
* Obviously all of this could have been accomplished without calling into the activity
* and then back into javascript, but this code is intended to show how to set up the
* code paths for this sort of communication.
*
*/
public class WebViewDemo extends Activity { private static final String LOG_TAG = "WebViewDemo"; private WebView mWebView; private Handler mHandler = new Handler(); @Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
setContentView(R.layout.main);
mWebView = (WebView) findViewById(R.id.webview); WebSettings webSettings = mWebView.getSettings();
webSettings.setSavePassword(false);
webSettings.setSaveFormData(false);
webSettings.setJavaScriptEnabled(true);
webSettings.setSupportZoom(false); mWebView.setWebChromeClient(new MyWebChromeClient()); mWebView.addJavascriptInterface(new DemoJavaScriptInterface(), "demo"); mWebView.loadUrl("file:///android_asset/demo.html");
} final class DemoJavaScriptInterface { DemoJavaScriptInterface() {
} /**
* This is not called on the UI thread. Post a runnable to invoke
* loadUrl on the UI thread.
*/
public void clickOnAndroid() {
mHandler.post(new Runnable() {
public void run() {
mWebView.loadUrl("javascript:wave()");
}
}); }
} /**
* Provides a hook for calling "alert" from javascript. Useful for
* debugging your javascript.
*/
final class MyWebChromeClient extends WebChromeClient {
@Override
public boolean onJsAlert(WebView view, String url, String message, JsResult result) {
Log.d(LOG_TAG, message);
result.confirm();
return true;
}
}
}
th.setVisible(....)
跟你学习。