Posted By

iloveitaly on 04/30/07


anchor webview

Versions (?)

Who likes this?

2 people have marked this snippet as a favorite


Jump To HTML Anchor WebView

 / Published in: Objective C


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