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

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
nmw
Forum Newbie
Posts: 5
Joined: Tue May 30, 2006 3:19 am

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

Post 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?
josh
DevNet Master
Posts: 4872
Joined: Wed Feb 11, 2004 3:23 pm
Location: Palm beach, Florida

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

Post 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
nmw
Forum Newbie
Posts: 5
Joined: Tue May 30, 2006 3:19 am

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

Post 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.
josh
DevNet Master
Posts: 4872
Joined: Wed Feb 11, 2004 3:23 pm
Location: Palm beach, Florida

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

Post by josh »

yep
nmw
Forum Newbie
Posts: 5
Joined: Tue May 30, 2006 3:19 am

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

Post by nmw »

And the one that appears to work is:-

http://somewhere.com/myscript.php?index=12345#myanchor
josh
DevNet Master
Posts: 4872
Joined: Wed Feb 11, 2004 3:23 pm
Location: Palm beach, Florida

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

Post by josh »

glad i could help
Post Reply