WKWebView* webView = _realWebView;
NSString *jScript = @"var meta = document.createElement('meta');
meta.name = 'viewport';
meta.content = 'width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no';
var head = document.getElementsByTagName('head')[0];
head.appendChild(meta);";
if(scalesPageToFit)
{
WKUserScript *wkUScript = [[NSClassFromString(@"WKUserScript") alloc] initWithSource:jScript injectionTime:WKUserScriptInjectionTimeAtDocumentEnd forMainFrameOnly:NO];
[webView.configuration.userContentController addUserScript:wkUScript];
}
else
{
NSMutableArray* array = [NSMutableArray arrayWithArray:webView.configuration.userContentController.userScripts];
for (WKUserScript *wkUScript in array)
{
if([wkUScript.source isEqual:jScript])
{
[array removeObject:wkUScript];
break;
}
}
for (WKUserScript *wkUScript in array)
{
[webView.configuration.userContentController addUserScript:wkUScript];
}
}
webview.scalespagetofit只有UIWebView才有