0

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.

2
  • Possible duplicate of UIWebView: Can You Disable Javascript? Commented 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) Commented Nov 23, 2015 at 6:11

1 Answer 1

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)
Sign up to request clarification or add additional context in comments.

2 Comments

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.