Swift WKWebView禁用Javascript
我正在使用WKWebView
加载我的应用程序中的一些链接。 我想要禁用几乎所有网页上出现的恼人的JavaScript横幅。 有没有一个简单的function可以做到这一点?
WKWebView
有一个禁用JavaScript的configuration,请检查Apple的参考 。
var javaScriptEnabled: Bool
更新
let preferences = WKPreferences() preferences.javaScriptEnabled = false // Create a configuration for the preferences let configuration = WKWebViewConfiguration() configuration.preferences = preferences // Instantiate the web view webView = WKWebView(frame: view.bounds, configuration: configuration) // Load page if let theWebView = webView{ let url = NSURL(string: "http://www.apple.com") let urlRequest = NSURLRequest(URL: url!) theWebView.loadRequest(urlRequest) theWebView.navigationDelegate = self view.addSubview(theWebView) }
对于我们仍然使用Objective-C的人来说,这里是解决scheme:
WKPreferences *prefs = [[WKPreferences alloc]init]; prefs.javaScriptEnabled = NO; // Create a configuration for the preferences WKWebViewConfiguration *config = [[WKWebViewConfiguration alloc]init]; config.preferences = prefs; // Instantiate the web view _webView = [[WKWebView alloc]initWithFrame:[[UIScreen mainScreen]bounds] configuration:config];
- ARKit根据触摸位置设置ARAnchor变换
- FBRequest requestForMe startWithCompletionHandler方法不能在设备上工作
- iPhone’unuzdaolmasıgereken mobil oyunlar:Oddmar
- 是否有可能以编程方式closuresiOS中的拨号辅助function?
- 如何在显示启animation面的同时从networking服务加载数据?
- UIImageView.appearance重写了UISegmentedControl.appearance
- SpriteKit输送带
- 使用iOS 10预提取API增强平滑滚动
- 在Objective-C中使用GCC C扩展(语句expression式)进行初始化