Posted By

iloveitaly on 04/30/07


Tagged

anchor webview


Versions (?)

Who likes this?

2 people have marked this snippet as a favorite

ericj
tcol


Jump To HTML Anchor WebView


 / Published in: Objective C
 

URL: http://mabblog.com/

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.

  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. }

Report this snippet  

You need to login to post a comment.