A top-of-current-page button that works properly in XHTML doesn’t work properly using MODx.
The button is part of a fluid layout that may result in quite long pages. As a convenience to the reader, I include a button in the page footer that causes the view to jump to the top of the current page. This works as intended in the original XHTML: Click the button at the bottom of index.html and the top of index.html appears in the viewport. Click the button at the bottom of child.html and the top of child.html appears.
Since the footer code is the same for every page, MODx allows me to abstract it as a Chunk and then refer to that Chunk in Templates. (I have one Template for the root Page, another for child Pages.) The Pages have no content of their own, just point at the Templates. (If I weren’t using MODx, I’d accomplish this with a PHP Include.)
I browse to the root Page of the MODx hierarchy and have a look. Then I browse to the child Page. I find that clicking that button at the bottom of the root Page causes the top of that Page to appear, as desired. However, a click on that button on a child Page also causes the top of the root Page to appear, which is not the desired behavior.
Checking the source code generated for each page shows that the footer XHTML is identical, just as expected. Therefore, I conclude that the machinery that sets the page-number argument passed in the URL is getting confused. What causes the confusion, and how do I work around it?
Here is the XHTML:
<body>
<a name="pagetop"></a>
.
.
.
.
<div id="footer">
<form action="#pagetop">
<button id="go_pagetop" type="submit">
Jump to Top of Page
</button>
</form>
<div>
<p id="foot_blurb">
Paid for and © Copyright 2010 by Groton Republican Town Committee<br/>
P.O. Box 472, Groton, MA 01450
— Brooks T. Lyman, Treasurer
</p>
</div>
</div>
</div>
</body>
Thanks!