UIWebView: Can I disable the javascript alert() inside any web page?

前端 未结 4 1988
情深已故
情深已故 2020-12-14 19:27

I am using UIWebView to load a URL.

Inside the page of that URL, it uses alert(\"whatever msg\") as JavaScript. My UIWebView w

4条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-14 19:56

    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;.

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

    You can find the answer here: https://stackoverflow.com/a/21698251/2377378

提交回复
热议问题