WKWebView is not scrolling the content to mapped HTML
I am working on the WKWebView to render the HTML in WKWebView.
My HTML has <a href ='#bottom'>
This anchor tag will push my WKWebView to the content mapped to it.
My full HTML is :
<!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>
My Code to handle the link button is as below:
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
When click on the anchor tag it should scroll WKWebview to the content mapped to it in HTML which is not happening.
I am using Xcode 10 and working on iOS 11
I don't know what is missing I have tried almost everything but it is not scrolling to mapped data in anchor tag to have a view of HTML , you can paste my HTML in
https://codebeautify.org/htmlviewer/
Please check and let me know what am I missing.
thank you in advance. :)
ios swift wkwebview xcode10 wknavigationdelegate
add a comment |
I am working on the WKWebView to render the HTML in WKWebView.
My HTML has <a href ='#bottom'>
This anchor tag will push my WKWebView to the content mapped to it.
My full HTML is :
<!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>
My Code to handle the link button is as below:
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
When click on the anchor tag it should scroll WKWebview to the content mapped to it in HTML which is not happening.
I am using Xcode 10 and working on iOS 11
I don't know what is missing I have tried almost everything but it is not scrolling to mapped data in anchor tag to have a view of HTML , you can paste my HTML in
https://codebeautify.org/htmlviewer/
Please check and let me know what am I missing.
thank you in advance. :)
ios swift wkwebview xcode10 wknavigationdelegate
add a comment |
I am working on the WKWebView to render the HTML in WKWebView.
My HTML has <a href ='#bottom'>
This anchor tag will push my WKWebView to the content mapped to it.
My full HTML is :
<!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>
My Code to handle the link button is as below:
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
When click on the anchor tag it should scroll WKWebview to the content mapped to it in HTML which is not happening.
I am using Xcode 10 and working on iOS 11
I don't know what is missing I have tried almost everything but it is not scrolling to mapped data in anchor tag to have a view of HTML , you can paste my HTML in
https://codebeautify.org/htmlviewer/
Please check and let me know what am I missing.
thank you in advance. :)
ios swift wkwebview xcode10 wknavigationdelegate
I am working on the WKWebView to render the HTML in WKWebView.
My HTML has <a href ='#bottom'>
This anchor tag will push my WKWebView to the content mapped to it.
My full HTML is :
<!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>
My Code to handle the link button is as below:
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
When click on the anchor tag it should scroll WKWebview to the content mapped to it in HTML which is not happening.
I am using Xcode 10 and working on iOS 11
I don't know what is missing I have tried almost everything but it is not scrolling to mapped data in anchor tag to have a view of HTML , you can paste my HTML in
https://codebeautify.org/htmlviewer/
Please check and let me know what am I missing.
thank you in advance. :)
ios swift wkwebview xcode10 wknavigationdelegate
ios swift wkwebview xcode10 wknavigationdelegate
edited Nov 13 '18 at 16:43
rmaddy
245k27324388
245k27324388
asked Nov 13 '18 at 10:04
Raghav ChopraRaghav Chopra
401722
401722
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
- Make sure that your HTML validates - your use of
<p>
tag is invalid (headers<h3>
cannot reside in p tags e.g.);<title></title>
is required name
is now obsolete, useid
attribute instead on nearest container e.g. on the enclosingdiv
element
import UIKit
import WebKit
class ViewController: UIViewController
let webView = WKWebView()
override func viewDidLoad()
super.viewDidLoad()
self.view.addSubview(webView)
let html = "<!DOCTYPE html><html xmlns='http://www.w3.org/1999/xhtml'><head> <title>Hello</title><style>body font-size: 40px;</style> </head><body><a name='LnkTop'></a><p><a href='#bottom'> Link 1</a></p><div> <h3><a name='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 features for 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>"
webView.loadHTMLString(html, baseURL: nil)
webView.topAnchor.constraint(equalTo: self.view.topAnchor).isActive = true
webView.leftAnchor.constraint(equalTo: self.view.leftAnchor).isActive = true
webView.rightAnchor.constraint(equalTo: self.view.rightAnchor).isActive = true
webView.bottomAnchor.constraint(equalTo: self.view.bottomAnchor).isActive = true
webView.translatesAutoresizingMaskIntoConstraints = false
When I run my HTML in HTML Viwer it is working fine.Can you please change the HTML as per your advise and let me check
– Raghav Chopra
Nov 13 '18 at 11:16
I tried your piece of code in my view controller and it is not working as expected I think HTML needs to be corrected.
– Raghav Chopra
Nov 13 '18 at 11:20
The fact that HTML renders "fine" in a browser or a viewer does not mean it's correct (engines try to fix a lot of issues on your behalf). Use validator.w3.org/nu/#textarea to verify it.
– Peter Pajchl
Nov 13 '18 at 11:26
I have changed my html as per the validator and it is still not solving the purpose.When I click on the Link 1 it should drag me to the tag associated with that anchor tag. I hope you understand what I am saying
– Raghav Chopra
Nov 13 '18 at 11:38
I have edited my question and added the latest html to it after the validator test
– Raghav Chopra
Nov 13 '18 at 11:39
|
show 10 more comments
Well I would like to close my question
The above answer worked for me in iOS 12.0
it is not working on the Lower version
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53278456%2fwkwebview-is-not-scrolling-the-content-to-mapped-html%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
- Make sure that your HTML validates - your use of
<p>
tag is invalid (headers<h3>
cannot reside in p tags e.g.);<title></title>
is required name
is now obsolete, useid
attribute instead on nearest container e.g. on the enclosingdiv
element
import UIKit
import WebKit
class ViewController: UIViewController
let webView = WKWebView()
override func viewDidLoad()
super.viewDidLoad()
self.view.addSubview(webView)
let html = "<!DOCTYPE html><html xmlns='http://www.w3.org/1999/xhtml'><head> <title>Hello</title><style>body font-size: 40px;</style> </head><body><a name='LnkTop'></a><p><a href='#bottom'> Link 1</a></p><div> <h3><a name='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 features for 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>"
webView.loadHTMLString(html, baseURL: nil)
webView.topAnchor.constraint(equalTo: self.view.topAnchor).isActive = true
webView.leftAnchor.constraint(equalTo: self.view.leftAnchor).isActive = true
webView.rightAnchor.constraint(equalTo: self.view.rightAnchor).isActive = true
webView.bottomAnchor.constraint(equalTo: self.view.bottomAnchor).isActive = true
webView.translatesAutoresizingMaskIntoConstraints = false
When I run my HTML in HTML Viwer it is working fine.Can you please change the HTML as per your advise and let me check
– Raghav Chopra
Nov 13 '18 at 11:16
I tried your piece of code in my view controller and it is not working as expected I think HTML needs to be corrected.
– Raghav Chopra
Nov 13 '18 at 11:20
The fact that HTML renders "fine" in a browser or a viewer does not mean it's correct (engines try to fix a lot of issues on your behalf). Use validator.w3.org/nu/#textarea to verify it.
– Peter Pajchl
Nov 13 '18 at 11:26
I have changed my html as per the validator and it is still not solving the purpose.When I click on the Link 1 it should drag me to the tag associated with that anchor tag. I hope you understand what I am saying
– Raghav Chopra
Nov 13 '18 at 11:38
I have edited my question and added the latest html to it after the validator test
– Raghav Chopra
Nov 13 '18 at 11:39
|
show 10 more comments
- Make sure that your HTML validates - your use of
<p>
tag is invalid (headers<h3>
cannot reside in p tags e.g.);<title></title>
is required name
is now obsolete, useid
attribute instead on nearest container e.g. on the enclosingdiv
element
import UIKit
import WebKit
class ViewController: UIViewController
let webView = WKWebView()
override func viewDidLoad()
super.viewDidLoad()
self.view.addSubview(webView)
let html = "<!DOCTYPE html><html xmlns='http://www.w3.org/1999/xhtml'><head> <title>Hello</title><style>body font-size: 40px;</style> </head><body><a name='LnkTop'></a><p><a href='#bottom'> Link 1</a></p><div> <h3><a name='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 features for 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>"
webView.loadHTMLString(html, baseURL: nil)
webView.topAnchor.constraint(equalTo: self.view.topAnchor).isActive = true
webView.leftAnchor.constraint(equalTo: self.view.leftAnchor).isActive = true
webView.rightAnchor.constraint(equalTo: self.view.rightAnchor).isActive = true
webView.bottomAnchor.constraint(equalTo: self.view.bottomAnchor).isActive = true
webView.translatesAutoresizingMaskIntoConstraints = false
When I run my HTML in HTML Viwer it is working fine.Can you please change the HTML as per your advise and let me check
– Raghav Chopra
Nov 13 '18 at 11:16
I tried your piece of code in my view controller and it is not working as expected I think HTML needs to be corrected.
– Raghav Chopra
Nov 13 '18 at 11:20
The fact that HTML renders "fine" in a browser or a viewer does not mean it's correct (engines try to fix a lot of issues on your behalf). Use validator.w3.org/nu/#textarea to verify it.
– Peter Pajchl
Nov 13 '18 at 11:26
I have changed my html as per the validator and it is still not solving the purpose.When I click on the Link 1 it should drag me to the tag associated with that anchor tag. I hope you understand what I am saying
– Raghav Chopra
Nov 13 '18 at 11:38
I have edited my question and added the latest html to it after the validator test
– Raghav Chopra
Nov 13 '18 at 11:39
|
show 10 more comments
- Make sure that your HTML validates - your use of
<p>
tag is invalid (headers<h3>
cannot reside in p tags e.g.);<title></title>
is required name
is now obsolete, useid
attribute instead on nearest container e.g. on the enclosingdiv
element
import UIKit
import WebKit
class ViewController: UIViewController
let webView = WKWebView()
override func viewDidLoad()
super.viewDidLoad()
self.view.addSubview(webView)
let html = "<!DOCTYPE html><html xmlns='http://www.w3.org/1999/xhtml'><head> <title>Hello</title><style>body font-size: 40px;</style> </head><body><a name='LnkTop'></a><p><a href='#bottom'> Link 1</a></p><div> <h3><a name='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 features for 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>"
webView.loadHTMLString(html, baseURL: nil)
webView.topAnchor.constraint(equalTo: self.view.topAnchor).isActive = true
webView.leftAnchor.constraint(equalTo: self.view.leftAnchor).isActive = true
webView.rightAnchor.constraint(equalTo: self.view.rightAnchor).isActive = true
webView.bottomAnchor.constraint(equalTo: self.view.bottomAnchor).isActive = true
webView.translatesAutoresizingMaskIntoConstraints = false
- Make sure that your HTML validates - your use of
<p>
tag is invalid (headers<h3>
cannot reside in p tags e.g.);<title></title>
is required name
is now obsolete, useid
attribute instead on nearest container e.g. on the enclosingdiv
element
import UIKit
import WebKit
class ViewController: UIViewController
let webView = WKWebView()
override func viewDidLoad()
super.viewDidLoad()
self.view.addSubview(webView)
let html = "<!DOCTYPE html><html xmlns='http://www.w3.org/1999/xhtml'><head> <title>Hello</title><style>body font-size: 40px;</style> </head><body><a name='LnkTop'></a><p><a href='#bottom'> Link 1</a></p><div> <h3><a name='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 features for 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>"
webView.loadHTMLString(html, baseURL: nil)
webView.topAnchor.constraint(equalTo: self.view.topAnchor).isActive = true
webView.leftAnchor.constraint(equalTo: self.view.leftAnchor).isActive = true
webView.rightAnchor.constraint(equalTo: self.view.rightAnchor).isActive = true
webView.bottomAnchor.constraint(equalTo: self.view.bottomAnchor).isActive = true
webView.translatesAutoresizingMaskIntoConstraints = false
edited Nov 13 '18 at 12:01
answered Nov 13 '18 at 10:43
Peter PajchlPeter Pajchl
2,2421624
2,2421624
When I run my HTML in HTML Viwer it is working fine.Can you please change the HTML as per your advise and let me check
– Raghav Chopra
Nov 13 '18 at 11:16
I tried your piece of code in my view controller and it is not working as expected I think HTML needs to be corrected.
– Raghav Chopra
Nov 13 '18 at 11:20
The fact that HTML renders "fine" in a browser or a viewer does not mean it's correct (engines try to fix a lot of issues on your behalf). Use validator.w3.org/nu/#textarea to verify it.
– Peter Pajchl
Nov 13 '18 at 11:26
I have changed my html as per the validator and it is still not solving the purpose.When I click on the Link 1 it should drag me to the tag associated with that anchor tag. I hope you understand what I am saying
– Raghav Chopra
Nov 13 '18 at 11:38
I have edited my question and added the latest html to it after the validator test
– Raghav Chopra
Nov 13 '18 at 11:39
|
show 10 more comments
When I run my HTML in HTML Viwer it is working fine.Can you please change the HTML as per your advise and let me check
– Raghav Chopra
Nov 13 '18 at 11:16
I tried your piece of code in my view controller and it is not working as expected I think HTML needs to be corrected.
– Raghav Chopra
Nov 13 '18 at 11:20
The fact that HTML renders "fine" in a browser or a viewer does not mean it's correct (engines try to fix a lot of issues on your behalf). Use validator.w3.org/nu/#textarea to verify it.
– Peter Pajchl
Nov 13 '18 at 11:26
I have changed my html as per the validator and it is still not solving the purpose.When I click on the Link 1 it should drag me to the tag associated with that anchor tag. I hope you understand what I am saying
– Raghav Chopra
Nov 13 '18 at 11:38
I have edited my question and added the latest html to it after the validator test
– Raghav Chopra
Nov 13 '18 at 11:39
When I run my HTML in HTML Viwer it is working fine.Can you please change the HTML as per your advise and let me check
– Raghav Chopra
Nov 13 '18 at 11:16
When I run my HTML in HTML Viwer it is working fine.Can you please change the HTML as per your advise and let me check
– Raghav Chopra
Nov 13 '18 at 11:16
I tried your piece of code in my view controller and it is not working as expected I think HTML needs to be corrected.
– Raghav Chopra
Nov 13 '18 at 11:20
I tried your piece of code in my view controller and it is not working as expected I think HTML needs to be corrected.
– Raghav Chopra
Nov 13 '18 at 11:20
The fact that HTML renders "fine" in a browser or a viewer does not mean it's correct (engines try to fix a lot of issues on your behalf). Use validator.w3.org/nu/#textarea to verify it.
– Peter Pajchl
Nov 13 '18 at 11:26
The fact that HTML renders "fine" in a browser or a viewer does not mean it's correct (engines try to fix a lot of issues on your behalf). Use validator.w3.org/nu/#textarea to verify it.
– Peter Pajchl
Nov 13 '18 at 11:26
I have changed my html as per the validator and it is still not solving the purpose.When I click on the Link 1 it should drag me to the tag associated with that anchor tag. I hope you understand what I am saying
– Raghav Chopra
Nov 13 '18 at 11:38
I have changed my html as per the validator and it is still not solving the purpose.When I click on the Link 1 it should drag me to the tag associated with that anchor tag. I hope you understand what I am saying
– Raghav Chopra
Nov 13 '18 at 11:38
I have edited my question and added the latest html to it after the validator test
– Raghav Chopra
Nov 13 '18 at 11:39
I have edited my question and added the latest html to it after the validator test
– Raghav Chopra
Nov 13 '18 at 11:39
|
show 10 more comments
Well I would like to close my question
The above answer worked for me in iOS 12.0
it is not working on the Lower version
add a comment |
Well I would like to close my question
The above answer worked for me in iOS 12.0
it is not working on the Lower version
add a comment |
Well I would like to close my question
The above answer worked for me in iOS 12.0
it is not working on the Lower version
Well I would like to close my question
The above answer worked for me in iOS 12.0
it is not working on the Lower version
answered Nov 14 '18 at 5:58
Raghav ChopraRaghav Chopra
401722
401722
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53278456%2fwkwebview-is-not-scrolling-the-content-to-mapped-html%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown