我正在预先加载并打开另一个WKWebView,以减少主WKWebView中其他网页的加载时间。
但是,每次打开和关闭另一个网页时,同一页面上都会有更多内容。当我关闭另一个网页时,我想删除正在关闭的网页。我该怎么办?
Main.js
$(document).ready(function(){
var data = {
apiType : "preload",
parameter : encodeURI(`view/other?value="testvalue"`)
}
webkit.messageHandlers.TestApp.postMessage(data);
...
$('#openBtn').on('click', function(){
var data = {
apiType : "openOther"
}
webkit.messageHandlers.TestApp.postMessage(data);
MainWKWebViewController.swift
func userContentController(_ userContentController: WKUserContentController, didReceive message: WKScriptMessage) {
case "preload":
let parameter = message["parameter"] as! String
preload(parameter)
break
case "openOther":
openOtherScreen()
break
...
func preload(_ prameter: String){
let storyboard = UIStoryboard(name: "Main", bundle: nil)
otherWebView = storyboard.instantiateViewController(withIdentifier: "OtherWebViewController") as? OtherWebViewController
otherWebView.delegate = self
otherWebView.paramFromMain = prameter
otherWebView.loadViewIfNeeded()
otherWebView.otherWebView.navigationDelegate = self
preloadCheck = true
}
func openOtherScreen(){
if preloadCheck {
DispatchQueue.main.async {
self.navigationController?.pushViewController(self.otherWebView, animated: true)
self.preloadCheck = false
}
} else {
}
}
...
extension MainWKWebViewController: OtherWKWebViewControllerDelegate {
func HandleData(_ key: String){
if key == "reload" {
self.mainWKWebView.reload()
}
}
}
OtherWKWebViewController.swift
case "Close":
self.delegate?.HandleData("reload")
self.navigationController?.popViewController(animated: true)
break
Safari =>开发=> TestIphone的WKwebViewList
我该如何解决这个问题?