Я работаю над WKWebView, чтобы отобразить HTML-код в WKWebView.
My HTML has <a href ='#bottom'>
Этот тег привязки подтолкнет мой WKWebView к отображаемому на него содержимому.Мой полный HTML-код:
<!DOCTYPE html><html lang="en"><head> <title>Hello</title><style>body{ font-size: 40px;}</style> </head><body><a id='LnkTop'></a><p><a href='#bottom'> Link 1</a></p><div><h3><a id='top'> Link 1 </a>click will bring cursor here..</h3><p>HTML offers many of the conventional publishing idioms for rich text and structured documents, but what separates it from most other markup languages is its featuresfor hypertext and interactive documents. This section introduces the link (or hyperlink, or Web link), the basic hypertext construct.A link is a connection from one Web resource to another. Although a simple concept, the link has been one of the primary forces driving the success of the Web.A link has two ends -- called anchors -- and a direction. The link starts at the 'source' anchor and points to the 'destination' anchor,which may be any Web resource (e.g., an image, a video clip, a sound bite, a program, an HTML document, an element within an HTML document, etc.).</p></div><div id='bottom'><h3>Link 2 click will bring cursor here..</h3><p>HTML offers many of the conventional publishing idioms for rich text and structured documents, but what separates it from most other markup languages is its featuresfor hypertext and interactive documents. This section introduces the link (or hyperlink, or Web link), the basic hypertext construct.A link is a connection from one Web resource to another. Although a simple concept, the link has been one of the primary forces driving the success of the Web.A link has two ends -- called anchors -- and a direction. The link starts at the 'source' anchor and points to the 'destination' anchor,which may be any Web resource (e.g., an image, a video clip, a sound bite, a program, an HTML document, an element within an HTML document, etc.).</p></div></body></html>
Мой код для обработки кнопки ссылки выглядит следующим образом:
func webView(_ webView: WKWebView, didReceiveServerRedirectForProvisionalNavigation navigation: WKNavigation!) {
print("Strat to load")
}
func webView(_ webView: WKWebView, shouldPreviewElement elementInfo: WKPreviewElementInfo) -> Bool {
print("Raghav")
return true
}
func webView(_ webView: WKWebView, didFailProvisionalNavigation navigation: WKNavigation!, withError error: Error) {
print(error.localizedDescription)
}
func webView(_ webView: WKWebView, didStartProvisionalNavigation navigation: WKNavigation!) {
print("Strat to load")
}
func webView(_ webView: WKWebView, didFinish navigation: WKNavigation!) {
print("finish to load")
webviewReportNotes.evaluateJavaScript("window.scrollTo(0,0)", completionHandler: nil)
}
func webView(_ webView: WKWebView, didFail navigation: WKNavigation!, withError error: Error) {
print("error ")
print(error)
}
func webView(_ webView: WKWebView, decidePolicyFor navigationAction: WKNavigationAction, decisionHandler: @escaping (WKNavigationActionPolicy) -> Void) {
print("clicked")
if navigationAction.navigationType == WKNavigationType.linkActivated {
print("cancel")
///webviewReportNotes.evaluateJavaScript("window.scrollTo(0,0)", completionHandler: nil)
decisionHandler(.cancel)
self.webviewReportNotes.allowsLinkPreview = true
// webView.load(navigationAction.request)
}
else
{
print("allow")
decisionHandler(.allow)
}
}
func webView(_ webView: WKWebView, didCommit navigation: WKNavigation!) {
print("comitted")
}
func webView(_ webView: WKWebView, createWebViewWith configuration: WKWebViewConfiguration, for navigationAction: WKNavigationAction, windowFeatures: WKWindowFeatures) -> WKWebView? {
print("entered")
if navigationAction.targetFrame == nil {
webView.load(navigationAction.request)
}
return nil
}
При щелчке по тегу привязки следует прокрутить WKWebview до сопоставленного с ним содержимого.в HTML этого не происходит.
I am using Xcode 10 and working on iOS 11
Я не знаю, чего не хватает, я перепробовал почти все, но он не прокручивается до сопоставленных данных в теге привязки, чтобы иметь представление HTML, вы можете вставитьмой HTML в
https://codebeautify.org/htmlviewer/
Пожалуйста, проверьте и дайте мне знать, что мне не хватает.
Заранее спасибо.:)