I would like to know how to disable javascript for web view in iOS?
I know this property javaScriptEnabled, but not finding any proper way to implement it.
-
Possible duplicate of UIWebView: Can You Disable Javascript?JAL– JAL2015-11-20 14:24:42 +00:00Commented Nov 20, 2015 at 14:24
-
but there must be some way right,coz for lots of browser on our devices there is functionality for disabling javascript(eg.Safari)admin– admin2015-11-23 06:11:04 +00:00Commented Nov 23, 2015 at 6:11
Add a comment
|
1 Answer
To use that property you will need to use a WKWebView instead of a UIWebView. This will limit you to supporting iOS8+.
Once you switch to using the WKWebView all you need to do is set the property on WKPreferences to false, and then set the WKWebViewConfiguration
In Swift this looks something like this:
let prefs = WKPreferences()
prefs.javaScriptEnabled = false
let config = WKWebViewConfiguration()
config.preferences = prefs
let webView = WKWebView(frame: CGRectMake(0, 0, 100, 100), configuration: config)
2 Comments
admin
Instead of using WKWebview is there a possibility I use UIWebview only,because I have certain tasks which are there in web view call back method..so I will have to make lot more changes I guess.
BinaryGuy
There is no API available for doing this with a UIWebView. You'll have to swap it to the WKWebView instead I'm afraid or provide a link to another webpage that doesn't have any javascript on there.