I'm trying to copy all loaded data from one WKWebView
to a new WKWebView
so all content would be loaded when new webView
is presented.
Any suggestion how to do this or what would be the best approach to this?
Asked
Active
Viewed 984 times
7
-
Hey, @PashaN did you manage to solve this? I'm stuck with the same problem as well. – spaceMonkey Feb 10 '18 at 17:28
-
@spaceMonkey No, i just used one web view. – PashaN Feb 12 '18 at 22:10
1 Answers
-1
I found a solution in Xamarin forms, i hope this can help you, please to understand the idea and not the code
async Task<List<object>> OnGetConfigurationRequestAsync()
{
await Task.Delay(1);
List<object> list = new List<object>();
list.Add(_configuration);
list.Add(_contentController);
return list;
}
async Task<object> OnSetConfigurationRequestAsync(List<object> list)
{
await Task.Delay(1);
if (list == null) return null;
WKWebViewConfiguration wkConfig = null;
WKUserContentController wkUser = null;
foreach (var item in list)
{
if (item is WKWebViewConfiguration)
wkConfig = (WKWebViewConfiguration)item;
else if (item is WKUserContentController)
wkUser = (WKUserContentController)item;
}
if(wkConfig!=null)
{
_configuration = wkConfig;
_contentController = wkUser;
}
var wkWebView = new WKWebView(Frame, _configuration)
{
Opaque = false,
UIDelegate = this,
NavigationDelegate = _navigationDelegate,
};
SetNativeControl(wkWebView);
OnControlChanged?.Invoke(this, wkWebView);
return null;
}
When you instantiate a new webview, you have to copy configuration in this way:
private async Task CopyConfiguration(String url, MgFormsWebView mainWebview)
{
var config = await mainWebview.GetConfigurationAsync();
await webview.SetConfigurationAsync(config);
webview.Source = url;
}

StefanoM5
- 1,327
- 1
- 24
- 34