Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Disable Javascript in UIWebView

My iOS app needs to display very basic HTML received from a third party (using loadHTMLString with nil as baseURL).

Using a UIWebView was simple enough, however - I have a security concern since this view can also run Javascript, which is not allowed and also unnecessary for my app.

Is there a way to disable the app from running javascript? If not - does anyone know of a good sanitizing code to remove any malicious stuff (yet keep the regular HTML) from an NSString?

Thanks, Lior

like image 331
Lior Z Avatar asked Feb 27 '26 02:02

Lior Z


1 Answers

have you tried to use WKWebView it have the configuration option where you can set

javaScriptEnabled = NO;

https://developer.apple.com/library/ios/documentation/WebKit/Reference/WKPreferences_Ref/index.html#//apple_ref/occ/instp/WKPreferences/javaScriptEnabled

like image 120
Igor Avatar answered Feb 28 '26 14:02

Igor



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!