Jump To HTML Anchor WebView


/ Published in: Objective C
Save to your folder(s)

There is no native Cocoa way to do this, and this method was not advertised on the net much.
This is the only way to jump to a named anchor programatically.


Copy this code and paste it in your HTML
  1. - (void) jumpToAnchor:(NSString *)anchor {
  2. // http://lists.apple.com/archives/Webcore-dev/2003/Jul/msg00004.html
  3. [oWebView stringByEvaluatingJavaScriptFromString:[NSString stringWithFormat:@"var anchor = document.anchors[\"%@\"];window.scrollTo(anchor.offsetLeft, anchor.offsetTop);", anchor]];
  4. }

URL: http://mabblog.com/

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.