Reality.sys corrupted! Universe halted! Reboot?

jBookmarker and page anchors jBookmarker and page anchors

Raul Ionescu (see his projects on SourceForge: myAJAX and RC4PHP) keeps bugging me every now and then on the fact that my jBookmarker library prevents the use of page anchors. Yes, it does. But you can use the following workaround to simulate them.

Scroll to an element

The solution is simple and elegant. It makes use of the window.scroll method and my position retrieval scripts.
The usual markup for page anchors uses <a name=”whatever”> constructions, although this is not required, as the id of any element on the page can be used as an anchor. But if you like it this way, you’ll need to make some small adjustments:

<a name=”chapter_1″ id=”chapter_1″></a>

Of course, the layout of the URI must also be altered in order to work with jBookmarker. Such as:

http://www.foo.com/bar.html#goto=chapter_1

And all we need now is an onload javascript function, to scroll down the page:

window.onload = function() {
var goto = jBookmarker.get( 'goto' );
if ( !goto ) {
return;
}
var e = document.getElementById( goto );
if ( !e ) {
return;
}
window.scroll( 0, e.getPosition().y );
}

It works! Get it while it’s hot.

similarposts (presented by Monkey)

Monkey

comments...comments...0comments

There are no comments so far. But don't let that get in your way! Speak your mind

yourReply