如果您正在构建iOS 10.0,则应使用
WKWebView
相反它支持禁用javascript,也是推荐使用的组件。
首先创建preferences对象。您需要在创建web视图之前进行设置。
WKPreferences *preferences = [[WKPreferences alloc] init];
preferences.javaScriptEnabled = NO; // Here its set
// Other things you might want to disable
preferences.javaScriptCanOpenWindowsAutomatically = NO;
然后创建保存首选项的配置对象。
WKWebViewConfiguration *configuration = [[WKWebViewConfiguration alloc] init];
configuration.preferences = preferences;
然后创建web视图。
WKWebView *webView = [[WKWebView alloc] initWithFrame:frame configuration:configuration];
Read more about WKWebView here