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.
Asked
Active
Viewed 1,889 times
0
-
Possible duplicate of [UIWebView: Can You Disable Javascript?](http://stackoverflow.com/questions/2302975/uiwebview-can-you-disable-javascript) – JAL Nov 20 '15 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 Nov 23 '15 at 06:11
1 Answers
0
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)

BinaryGuy
- 1,246
- 1
- 15
- 29
-
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. – admin Nov 23 '15 at 06:09
-
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. – BinaryGuy Nov 23 '15 at 17:23