<legend id='mMkbb'><style id='mMkbb'><dir id='mMkbb'><q id='mMkbb'></q></dir></style></legend>
    • <bdo id='mMkbb'></bdo><ul id='mMkbb'></ul>
  • <small id='mMkbb'></small><noframes id='mMkbb'>

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

        <tfoot id='mMkbb'></tfoot>

        如何在渲染完成之前阻止 UIWebView 中的 Javascript 警报|确认|提示?

        时间:2023-10-21

          <tbody id='yDP82'></tbody>

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

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

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

                • <bdo id='yDP82'></bdo><ul id='yDP82'></ul>
                  <i id='yDP82'><tr id='yDP82'><dt id='yDP82'><q id='yDP82'><span id='yDP82'><b id='yDP82'><form id='yDP82'><ins id='yDP82'></ins><ul id='yDP82'></ul><sub id='yDP82'></sub></form><legend id='yDP82'></legend><bdo id='yDP82'><pre id='yDP82'><center id='yDP82'></center></pre></bdo></b><th id='yDP82'></th></span></q></dt></tr></i><div id='yDP82'><tfoot id='yDP82'></tfoot><dl id='yDP82'><fieldset id='yDP82'></fieldset></dl></div>
                  本文介绍了如何在渲染完成之前阻止 UIWebView 中的 Javascript 警报|确认|提示?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  关于 SO 的多个问题已经解决了类似的问题,但没有一个回答我的确切问题类型.大多数答案涉及运行 JS 片段并重载警报方法,如下所示:window.alert = function() {};

                  There are multiple questions on SO already addressing similar issues but none answers my exact type of question. Most of the answers involves running a JS snippet and overloading the alert method as such: window.alert = function() {};

                  我遇到的问题是加载的网页(我无法控制内容)在整个页面的呈现完成之前打开一个警报.

                  The problem I am having is that the webpage loaded (which I have no control over the content) opens an alert before the rendering of the whole page completes.

                  因此,我无法使用:- (void)webViewDidFinishLoad:(UIWebView *)webView 委托方法来运行 JS 片段.此外,在 - (void)webViewDidStartLoad:(UIWebView *)webView 中运行相同的代码段对我没有任何好处,因为它在加载 DOM 之前执行.

                  Because of this I cannot use the: - (void)webViewDidFinishLoad:(UIWebView *)webView delegate method to run the JS snippet. In addition running the same snippet in - (void)webViewDidStartLoad:(UIWebView *)webView won't do me any good since it executes before the DOM is loaded.

                  类似问题:

                  • 在 UIWebView 中捕获(和阻止)alert() 模态
                  • 我可以在 UIWebViewDelegate 中处理警报吗?
                  • UIWebView:我可以禁用 javascriptalert() 在任何网页中?

                  这方面有什么建议吗?

                  推荐答案

                  在尝试了一些有关注入 Javascript 的建议解决方案后,我回到了原生平台.

                  After experimenting a bit with the suggested solutions regarding injecting a Javascript I fell back on the native platform.

                  由于 UIWebView 将所有 Javascript 警报转换为本机 UIAlertViews,因此在本机端阻止它相当简单.查看 UIAlertView.h 只有一种公共方法可以方便地显示警报:- (void)show;.

                  Since a UIWebView translates all Javascript alerts into native UIAlertViews it is fairly simple to block it on the native end. Looking into UIAlertView.h there is only one public method for showing an alert which is conveniently called: - (void)show;.

                  此方法可以很容易地在子类中或通过类别被覆盖.我最终使用了一个类别,因为 文档 提到子类化 UIAlertView 的警告.

                  This method can easily be either overridden in a subclass or through a category. I ended up using a category since the documentation mentions a warning for subclassing UIAlertView.

                  @interface UIAlertView (Blocker)
                  @end
                  
                  #import "UIAlertView+Blocker.h"
                  
                  @implementation UIAlertView (Blocker)
                  
                  - (void)show {
                     return;
                  }
                  @end
                  

                  在包含 UIWebView 的视图控制器中导入此类别将阻止 UIAlertView 的所有实例,进而阻止所有 JS 警报.

                  Importing this category in the view controller that holds the UIWebView will block all instances of UIAlertView and in turn also all JS alerts.

                  我发现这个解决方案更强大,因为它不依赖于注入 Javascript、更改 HTML 或使用第三方库.它也与时间无关(JS-alert 代码可以在 header、body 或某些第三方库中).

                  I find this solution more robust since it does not rely on injecting Javascripts, changing HTML or using a third party library. It is also unrelated to timing (the JS-alert code can be in the header, body or in some third party lib).

                  这篇关于如何在渲染完成之前阻止 UIWebView 中的 Javascript 警报|确认|提示?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:Android-listview、服务媒体播放器和布尔标志 下一篇:WKWebView 与 UIWebView

                  相关文章

                  1. <tfoot id='52LdN'></tfoot>

                  2. <small id='52LdN'></small><noframes id='52LdN'>

                    <legend id='52LdN'><style id='52LdN'><dir id='52LdN'><q id='52LdN'></q></dir></style></legend>

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