<i id='J9Ldo'><tr id='J9Ldo'><dt id='J9Ldo'><q id='J9Ldo'><span id='J9Ldo'><b id='J9Ldo'><form id='J9Ldo'><ins id='J9Ldo'></ins><ul id='J9Ldo'></ul><sub id='J9Ldo'></sub></form><legend id='J9Ldo'></legend><bdo id='J9Ldo'><pre id='J9Ldo'><center id='J9Ldo'></center></pre></bdo></b><th id='J9Ldo'></th></span></q></dt></tr></i><div id='J9Ldo'><tfoot id='J9Ldo'></tfoot><dl id='J9Ldo'><fieldset id='J9Ldo'></fieldset></dl></div>

        <bdo id='J9Ldo'></bdo><ul id='J9Ldo'></ul>
      <tfoot id='J9Ldo'></tfoot>

      <small id='J9Ldo'></small><noframes id='J9Ldo'>

      <legend id='J9Ldo'><style id='J9Ldo'><dir id='J9Ldo'><q id='J9Ldo'></q></dir></style></legend>
      1. webview 不显示 javascript windows.open()

        webview don#39;t display javascript windows.open()(webview 不显示 javascript windows.open())

          • <i id='JVcdP'><tr id='JVcdP'><dt id='JVcdP'><q id='JVcdP'><span id='JVcdP'><b id='JVcdP'><form id='JVcdP'><ins id='JVcdP'></ins><ul id='JVcdP'></ul><sub id='JVcdP'></sub></form><legend id='JVcdP'></legend><bdo id='JVcdP'><pre id='JVcdP'><center id='JVcdP'></center></pre></bdo></b><th id='JVcdP'></th></span></q></dt></tr></i><div id='JVcdP'><tfoot id='JVcdP'></tfoot><dl id='JVcdP'><fieldset id='JVcdP'></fieldset></dl></div>
              <tbody id='JVcdP'></tbody>

            <small id='JVcdP'></small><noframes id='JVcdP'>

              <bdo id='JVcdP'></bdo><ul id='JVcdP'></ul>

              <legend id='JVcdP'><style id='JVcdP'><dir id='JVcdP'><q id='JVcdP'></q></dir></style></legend>

                <tfoot id='JVcdP'></tfoot>

                1. 本文介绍了webview 不显示 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() do run 并且从 Log.d() 我可以看到正确的 URL弹出窗口已提供给 WebView.

                  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 :(

                  实际上,也许 URL 并不完全正确……在 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...

                  推荐答案

                  首先,你需要在你的WebView上进行如下设置:

                  First of all, you need to set the following settings on your WebView:

                  WebSettings webSettings = webView.getSettings();
                  webSettings.setJavaScriptEnabled(true);
                  webSettings.setJavaScriptCanOpenWindowsAutomatically(true);
                  webSettings.setSupportMultipleWindows(true);
                  

                  然后您需要附加一个覆盖 onCreateWindowWebChromeClient.您对该方法的实现可以创建一个新的 Web 视图,并将其显示在对话框中:

                  Then you need to attach a WebChromeClient that overrides onCreateWindow. Your implementation of this method can create a new web view, and display it inside a dialog:

                  webView.setWebChromeClient(new WebChromeClient() {
                  
                          @Override
                          public boolean onCreateWindow(WebView view, boolean isDialog, boolean isUserGesture, Message resultMsg) {
                              WebView newWebView = new WebView(MyActivity.this);
                              WebSettings webSettings = newWebView.getSettings();
                              webSettings.setJavaScriptEnabled(true);
                  
                              // Other configuration comes here, such as setting the WebViewClient
                  
                              final Dialog dialog = new Dialog(MyActivity.this);
                              dialog.setContentView(newWebView);
                              dialog.show();
                  
                              newWebView.setWebChromeClient(new WebChromeClient() {
                                  @Override
                                  public void onCloseWindow(WebView window) {
                                      dialog.dismiss();
                                  }
                              });
                  
                              ((WebView.WebViewTransport)resultMsg.obj).setWebView(newWebView);
                              resultMsg.sendToTarget();
                              return true;
                          }
                  
                  });
                  

                  不要忘记将新的 web 视图设置为 resultMsg,将其发送到其目标并返回 true,如 API 文档.

                  Don't forget to set the new web view to the resultMsg, send it to its target and return true, as mentioned in the API documentation.

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

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  Sqlite database not copied from asset folder Android(Sqlite 数据库未从资产文件夹 Android 复制)
                  SQLite Database Copy Appears Corrupted When Generated by Device and not Emulator(SQLite 数据库副本在由设备而不是模拟器生成时出现损坏)
                  WebKit on th iPhone: is it possible to copy text to the clipboad with JavaScript(iPhone上的WebKit:是否可以使用JavaScript将文本复制到剪贴板)
                  Android file copy(安卓文件拷贝)
                  Android how to detect Copy event of Edittext in android(Android如何在android中检测Edittext的Copy事件)
                  Selecting text in mobile Safari on iPhone(在 iPhone 上的移动 Safari 中选择文本)
                  <legend id='ZKsIR'><style id='ZKsIR'><dir id='ZKsIR'><q id='ZKsIR'></q></dir></style></legend>
                  <i id='ZKsIR'><tr id='ZKsIR'><dt id='ZKsIR'><q id='ZKsIR'><span id='ZKsIR'><b id='ZKsIR'><form id='ZKsIR'><ins id='ZKsIR'></ins><ul id='ZKsIR'></ul><sub id='ZKsIR'></sub></form><legend id='ZKsIR'></legend><bdo id='ZKsIR'><pre id='ZKsIR'><center id='ZKsIR'></center></pre></bdo></b><th id='ZKsIR'></th></span></q></dt></tr></i><div id='ZKsIR'><tfoot id='ZKsIR'></tfoot><dl id='ZKsIR'><fieldset id='ZKsIR'></fieldset></dl></div>
                    <tbody id='ZKsIR'></tbody>
                2. <small id='ZKsIR'></small><noframes id='ZKsIR'>

                    <bdo id='ZKsIR'></bdo><ul id='ZKsIR'></ul>

                      1. <tfoot id='ZKsIR'></tfoot>