Searching for text inside SVG with browser (ctrl-f)

1,393 views
Skip to first unread message

Bob Monteverde

unread,
Nov 30, 2011, 3:50:42 PM11/30/11
to d3-js
Ok, this is a slightly random one, but interested to hear if anyone
has attempted something similar.

A coworker asked for the functionality that you could search for a
string that's in an SVG:TEXT field by using the browser's built in
search (specifically in FF and chrome). I had never tested this, so
just gave it a try. The browser does appear to pick up the text as I
had hoped, BUT, unlike normal search, it doesn't highlight the text
inside the SVG, it does appear to scroll to make it visible, but
hardly the ideal functionality (I guess its good that the user knows
its SOMEWHERE on the screen, but would like it pin-pointed). I'm
wondering if there's an event or something I can look for... or
similar, so I could highlight the text manually on the event.

Any insight on this would be very helpful.

Thanks,

Bob

Bob Monteverde

unread,
Dec 1, 2011, 9:21:12 AM12/1/11
to d3-js
Anyone know how I would watch the text node to see if any events are
called on it while searching? I've never tried to interact with the
built-in browser search before, not even sure if its possible.

Thanks,

Bob

Chris Viau

unread,
Dec 1, 2011, 9:53:14 AM12/1/11
to d3...@googlegroups.com
There is a working example here integrating HTML into SVG with foreignObject: http://starkravingfinkle.org/blog/2007/07/firefox-3-svg-foreignobject/ The found texts are highlighted.

Bob Monteverde

unread,
Dec 1, 2011, 11:24:33 AM12/1/11
to d3-js
Oh, very cool, looks like this should be perfect.. hope it works good
in all the supported browser on our platform.. looks like it should.
Reply all
Reply to author
Forward
0 new messages