Page 1 of 1

Setting 'scroll to' pos in PHP created page w/o javascript

Posted: Sat Sep 20, 2008 3:40 pm
by nmw
How do I set the 'scroll to' position in a page without using javascript?

I know how to do it with javascript, and I obviously know how to jump to a place in a page using anchors.

However, in this case, javascript is unlikely to be enabled in the browser, and the page is actually created on the fly using PHP, as opposed to being a normal HTML page with anchors embedded in it.

What I need to do as the result of a postback is to
- Create a page
- Select a point part way down it that I want scrolled into view
- Make sure that the page, when displayed in the browser, scrolls to and displays that part

How do I do that?

Re: Setting 'scroll to' pos in PHP created page w/o javascript

Posted: Sat Sep 20, 2008 8:35 pm
by josh
append #namedAnchor to the URL and redirect the browser, it will immediately jump to the named anchor on the page
Edit: hmm saw javascript is disabled, have the form post to a script, have that script output a Location header to redirect the browser

Re: Setting 'scroll to' pos in PHP created page w/o javascript

Posted: Sun Sep 21, 2008 1:43 am
by nmw
have the form post to a script, have that script output a Location header to redirect the browser
Yes, but how, exactly? A redirect would surely be something like http://somewhere.com/mypage#myanchor, but mypage doesn't actually exist as it is script generated.

Just had a thought though. The link in the original page that will cause all this would have been of the form

http://somewhere.com/myscript.php?index=12345

where 12345 tells the script how to build the page. I wonder if therefore

http://somewhere.com/myscript.php?index=12345#myanchor
or possibly
http://somewhere.com/myscript.php#myanchor?index=12345

might do it, if the script then builds the page with <a name=myanchor></a> in the appropriate place.

I'll try it.

Re: Setting 'scroll to' pos in PHP created page w/o javascript

Posted: Sun Sep 21, 2008 1:59 am
by josh
yep

Re: Setting 'scroll to' pos in PHP created page w/o javascript

Posted: Mon Sep 22, 2008 2:40 pm
by nmw
And the one that appears to work is:-

http://somewhere.com/myscript.php?index=12345#myanchor

Re: Setting 'scroll to' pos in PHP created page w/o javascript

Posted: Mon Sep 22, 2008 5:23 pm
by josh
glad i could help