0

I've got a UIWebView which is displaying a long chunk of HTML with multiple embedded images that are wrapped in links. The webview is scrollable so that content "below the fold" is accessible.

When the links are tapped, I'm using the webView:shouldStartLoadWithRequest:navigationType:navigationType method to catch a specific JavaScript call, which then triggers a modal load of a UIViewController over the top of the webview.

As soon as the link is tapped, the webview's contentOffset is reset to 0,0, so the page appears to "jump" back to the top. Ideally, I'd like the webView's contentOffset to remain where it is until the modal view controller is dismissed.

I've tried setting the webView.scrollView.scrollEnabled property to NO as soon as the shouldStartLoadWithRequest method is called - this doesn't stop the webView scrolling.

I've also tried saving the contentOffset value at the point where the link is tapped, and then manually resetting it - but again, this doesn't stop the webView from scrolling.

Is there any way of preventing this scrolling from happening??

1 Answer 1

0

This turns out to be nothing to do with UIWebView at all, and is standard browser behaviour.

The links in the HTML were in the form

<a href="#" onClick="window.open('js-call:image-xx');">
  <img src='foo.jpg'>
</a>

The problem was that I hadn't defined the # anchor, so the page was scrolling back to the top when the So altering the HTML to

<a name="image-xx">
<a href="image-xx" onClick="window.open('js-call:image-xx');">
  <img src='foo.jpg'>
</a>

fixes the issue.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.