We Recommend

Programming in Objective-C Programming in Objective-C
Programming in Objective-C is a concise, carefully written tutorial on the basics of Objective-C and object-oriented programming. The book makes no assumption about prior experience with object-oriented programming languages or with the C language (upon which Objective-C is based). And because of this, both novice and experienced programmers alike can use this book to quickly and effectively learn the fundamentals of Objective-C.


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.