Android 是否可能使用WebView OnCreateWindow创建弹出窗口(对话框样式)?比如安卓浏览器
当我在我的网络视图中按ebay.com上带有此代码的按钮时: 按钮的html:Android 是否可能使用WebView OnCreateWindow创建弹出窗口(对话框样式)?比如安卓浏览器,android,popup,Android,Popup,当我在我的网络视图中按ebay.com上带有此代码的按钮时: 按钮的html: input id="addPicturesBtn" name="addPicturesBtn" type="button" value="Add pictures" class="button" onclick="ebay.run(this.id,'onclick');return false;" onkeydown="ebay.run(this.id,'onkeydown');return false;" titl
input id="addPicturesBtn" name="addPicturesBtn" type="button" value="Add pictures" class="button" onclick="ebay.run(this.id,'onclick');return false;" onkeydown="ebay.run(this.id,'onkeydown');return false;" title="Add pictures"
如果在我的webview中按下此按钮,它会将新窗口从我的webview发送到android浏览器。但如果在android浏览器中按下相同的按钮,就会弹出这个很酷的对话框类型的弹出窗口(见图)
如果在我的webview中按下此按钮,我希望像浏览器一样打开易趣上的弹出式窗口。这样,当用户完成弹出时,它可以被用户关闭,并返回到我的应用程序
可能吗
以下是我到目前为止的情况:
webChromeClient = new WebChromeClient() {
@Override
public boolean onCreateWindow(WebView view, boolean dialog, boolean userGesture, Message resultMsg) {
WebView childView = new WebView(Ebay.this);
final WebSettings settings = childView.getSettings();
settings.setJavaScriptEnabled(true);
childView.setWebChromeClient(this);
childView.getSettings().setJavaScriptCanOpenWindowsAutomatically(true);
WebView.WebViewTransport transport = (WebView.WebViewTransport) resultMsg.obj;
transport.setWebView(childView);
resultMsg.sendToTarget();
return true;
}
@Override
public boolean onJsAlert(WebView view, String url, String message, JsResult result) {
new AlertDialog.Builder(view.getContext()).setMessage(message).setCancelable(true).show();
result.confirm();
return true;
}
我错过什么了吗
以下是android浏览器弹出窗口的图片(我正试图通过ebay.com上的按钮启动我的webview):
使用javascript接口。将javascript与java相结合,在java中创建自定义对话框 首先,启用javascript
webview.getSettings().setJavaScriptEnabled(true);
其次,您需要添加javascript接口
wv.addJavascriptInterface(new DemoJavaScriptInterface(), "js");
第三,加载url
webview.loadUrl("javascript:[javascript function name here]()");
这里有一些代码给你,希望能对你有所帮助
代码归功于名为“scottagarman”的开发人员。使用javascript接口。将javascript与java相结合,在java中创建自定义对话框 首先,启用javascript
webview.getSettings().setJavaScriptEnabled(true);
其次,您需要添加javascript接口
wv.addJavascriptInterface(new DemoJavaScriptInterface(), "js");
第三,加载url
webview.loadUrl("javascript:[javascript function name here]()");
这里有一些代码给你,希望能对你有所帮助
代码归功于名为“scottagarman”的开发人员。您可以按照他的方式完成:
public void onCreate(Bundle savedInstanceState){
....
webView.getSettings().setJavaScriptEnabled(true);
webView.addJavascriptInterface(new MyJSInterface(), "myappname");
webView.loadUrl("http://mysite.com/"); // or some local asset
....
}
public class MyJSInterface{
....
public void popup(){
// AlterDialog etc.
}
....
}
HTML from your website:
window.onload = function(){
window.myappname.popup();
}
我希望它对你有用
顺便说一句,2.3版时要小心,它有一个相应的,仅供参考的版本
public void onCreate(Bundle savedInstanceState){
....
webView.getSettings().setJavaScriptEnabled(true);
webView.addJavascriptInterface(new MyJSInterface(), "myappname");
webView.loadUrl("http://mysite.com/"); // or some local asset
....
}
public class MyJSInterface{
....
public void popup(){
// AlterDialog etc.
}
....
}
HTML from your website:
window.onload = function(){
window.myappname.popup();
}
我希望它对你有用
顺便说一句,2.3版时要小心,它有一个相应的,仅供参考的版本)您自己的方法走了多远?我现在也在尝试同样的事情。你目前的回答有点离题,因为他们假设这是你自己的网站(ebay不是)。你用自己的方法做了多少?我现在也在尝试同样的事情。你目前的答案有点离题,因为他们认为这是你自己的网站(ebay不是)。