swift 转 Object-clet web = WKWebViewinitframe CGRectinitx 0 y 100 width viewboundssizewidth height viewboundssizeheight - 100 let js = consolelog = functionoriLogFunc
#import <WebKit/WebKit.h>
WKWebView *web = [[WKWebView alloc] initWithFrame:CGRectMake(0, 100, CGRectGetWidth(self.view.bounds), CGRectGetHeight(self.view.bounds) - 100)];
NSString *js = @"console.log = (function(oriLogFunc){
return function(str){
oriLogFunc.call(console,str);
window.webkit.messageHandlers.log.postMessage(str);
}
})(console.log);";
WKUserScript *script = [[WKUserScript alloc] initWithSource:js injectionTime:WKUserScriptInjectionTimeAtDocumentStart forMainFrameOnly:NO];
[web.configuration.userContentController addUserScript:script];
[web.configuration.userContentController addScriptMessageHandler:self name:@"log"]
原文地址: http://www.cveoy.top/t/topic/iTnI 著作权归作者所有。请勿转载和采集!