网页视图不显示的JavaScript windows.open() [英] webview don't display javascript windows.open()

查看:343
本文介绍了网页视图不显示的JavaScript windows.open()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个的WebView 我在其中显示网页内容,我没有控制权。内容显示细腻,但它生成一个弹出窗口的链接。那这是否JavaScript函数如下:

I have a WebView in which i display web content which i have no control over. The content displays fine, but have links which spawn a popup window. The javascript function that does that looks like this:

function getEntry(id) {
var win = window.open('', 'Booking',
'resizable=yes,scrollbars=yes,status=no,width=500,height=400');
win.document.location = '/some/url/1-' + id ;
}

我不能轻易改变这一点,如果负责该页面的人,我下载要改变它,我想我的应用程序将惨遭失败...

I can't easily change this, and if the people responsible for the page i download would change it, i guess my app would fail miserably...

在活动中我的的WebView 设置是这样的:

My WebView setup in the activity looks like this:

    _webview = new WebView(this);
    setContentView(_webview);

    final Activity activity = this;
    _chromeClient = new MyChromeClient();

    _webview.setWebChromeClient(_chromeClient);

    //I experimented with changing user agent, in case that would have any effect, it didn't...
    _webview.getSettings().setUserAgentString("Mozilla/5.0 (Windows NT 5.1; rv:9.0.1) Gecko/20100101 Firefox/9.0.1");

    _webview.setWebViewClient(new MyWebViewClient());
    _webview.getSettings().setJavaScriptEnabled(true);
    _webview.getSettings().setJavaScriptCanOpenWindowsAutomatically(true);
    _webview.getSettings().setSupportZoom(true);
    _webview.getSettings().setBuiltInZoomControls(true);
    _webview.getSettings().setDomStorageEnabled(true);
    //Cache settings...
    _webview.getSettings().setAppCacheMaxSize(1024*1024*8);
    _webview.getSettings().setAppCachePath("/data/data/com.your.package.appname/cache");
    _webview.getSettings().setAllowFileAccess(true);
    _webview.getSettings().setAppCacheEnabled(true);

MyWebClient:

MyWebClient:

private class MyWebViewClient extends WebViewClient {

    @Override
    public void onLoadResource(WebView view, String url) {
        Log.d("MyWebViewClient",url);
    }
    @Override
    public boolean shouldOverrideUrlLoading(WebView view, String url) {
        showProgressDiag();
        Log.d("MyWebViewClient","shouldOverride... : " + url);
        view.loadUrl(url);
        return true;
    }
    @Override
    public void onPageFinished(WebView view, String url){
        hideProgressDiag();
    }
    @Override
    public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {

        if(failingUrl.equals("file:///android_asset/html/error.html")){
            hideProgressDiag();
            Toast.makeText(_context, "Error! Check internet connection, or try again later...", Toast.LENGTH_SHORT).show();
        }
        else {
            Toast.makeText(_context, failingUrl, Toast.LENGTH_SHORT).show();

            view.loadUrl("file:///android_asset/html/error.html");
        }

    }

}

MyChromeClient:

MyChromeClient:

private class MyChromeClient extends WebChromeClient{

    @Override
    public void onProgressChanged(WebView view, int progress) {
     Pdiag.setProgress(progress * 100);
    }

}

在单击指向JavaScript函数所发生的一切的链接之一就是的WebView 变为灰色,而无需通过 shouldOverrideUrlLoading会() 。当我打返回键的应用程序退出,这意味着什么也没有放在的WebView 的导航历史。有时什么也没有发生,但随后的 shouldOverrideUrlLoading() 不要运行并从 Log.d()我可以看到,弹出了正确的URL已经给web视图。

When clicking one of the links that points to the javascript function all that happens is that the WebView turns grey, without going through shouldOverrideUrlLoading(). When i hit the back key the app exits, meaning that nothing was placed in the nav history of the WebView. Sometimes nothing happens, but then the shouldOverrideUrlLoading() do run and from a Log.d() i can see that the correct URL for the popup has been given to the WebView.

问题是,在非常罕见的情况下它显示了罚款,但我不知道如何重现它,实际上还判定是否它显示在一个弹出。

The thing is, on very rare occasions it shows up fine, but i have no clue how to reproduce it, and wether it actually shows in a popup.

我迷路了......而相当沮丧......看着一个糟糕的情景喜剧,而不是思考:(

I'm lost... And quite frustrated... Thinking of watching a bad sitcom instead :(

编辑:
其实,也许网址是不是所有的纠正毕竟......在Firefox的URL以结束X<<<<但在我Log.d()输出,它与X%3C%3C%3C%3C结束...我会调查,如果我可以改变...

Actually, maybe the URL wasn't all that correct after all... In Firefox the URL ends with "X<<<<" but in my Log.d() output it ends with "X%3C%3C%3C%3C"... I'll investigate if i could change that...

编辑2:
不,什么也没做......的URL是相同的一个在Firefox ...

EDIT 2: Nope, didn't do anything... The URL is identical to the one in Firefox...

推荐答案

请与添加这个检查 -

Please check with adding this -

    getSettings().setSupportMultipleWindows(true);

这篇关于网页视图不显示的JavaScript windows.open()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆