SitePoint Sponsor |
|
User Tag List
Results 1 to 9 of 9
-
Jan 7, 2009, 14:09 #1
- Join Date
- Aug 2003
- Location
- Toronto
- Posts
- 119
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Positioning in Page Without # in URL
I'm working on a PHP app, adding comments functionality. The goal is to refresh the page (i.e. reload it), and position it at the appropriate spot (below the fold), but without specifying a # in the URL. I want the user to be able to save the URL without being brought back to exactly the same spot.
I epxect there is a way to do this; possibly with JavaScript. After all, when you hit a link which points within the same page, it doesn't reload the page; it just jumps to where it's supposed to go.
Any help would be appreciated.- A. Alfred Ayache
PHP/MySQL ZCE
-
Jan 7, 2009, 14:13 #2
- Join Date
- Apr 2006
- Location
- Maryland
- Posts
- 1,838
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Though I've never done this before, I'd assume you can do this by calculating the top offset of the element which you want to link to using a function such as gavin's findxy function, and then using the scrollTo method of the window object to get there.
-
Jan 7, 2009, 17:54 #3
- Join Date
- Aug 2003
- Location
- Toronto
- Posts
- 119
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Thanks, SoulScratch. After looking into it some, it turns out the intra-page link does add a #link to the URL after all... So I may as well just do it that way, and trust my users to know how to save a bookmark.
- A. Alfred Ayache
PHP/MySQL ZCE
-
Jan 8, 2009, 15:28 #4
- Join Date
- Aug 2003
- Location
- Toronto
- Posts
- 119
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
OK, so I linked to a URL like http://www.example.com/mypage.html?a=1&b=2#name. It went to the page, got the parameters, but didn't jump to the named anchor.
This was in FF 3. IE 7 worked fine. Chrome didn't go.
And yet, phpBB goes to the bottom of the page when you go to the last post in a thread.
Anyone have any idea why this would be?
Thx.- A. Alfred Ayache
PHP/MySQL ZCE
-
Jan 8, 2009, 16:03 #5
- Join Date
- Aug 2003
- Location
- Toronto
- Posts
- 119
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Hmmm, I may have an idea why it isn't jumping there.
The named anchor is actually hidden when the page is first loaded. One of the params indicates the tab should be displayed, but this only happens via JS after the page is loaded.
Bummer.
I may need to play around with this.
Oh well, it's not a deal breaker.
Thanks for listening.- A. Alfred Ayache
PHP/MySQL ZCE
-
Jan 8, 2009, 16:57 #6
- Join Date
- Aug 2003
- Location
- Toronto
- Posts
- 119
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Yep, that was it! The named anchor has to have a visible display property (i.e. not none).
- A. Alfred Ayache
PHP/MySQL ZCE
-
Jan 8, 2009, 18:54 #7
- Join Date
- Sep 2005
- Location
- Sydney, NSW, Australia
- Posts
- 16,875
- Mentioned
- 25 Post(s)
- Tagged
- 1 Thread(s)
Stephen J Chapman
javascriptexample.net, Book Reviews, follow me on Twitter
HTML Help, CSS Help, JavaScript Help, PHP/mySQL Help, blog
<input name="html5" type="text" required pattern="^$">
-
Jan 8, 2009, 21:10 #8
- Join Date
- Aug 2003
- Location
- Toronto
- Posts
- 119
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Sorry, no: I meant like <a name="commentform"></a>. Then you can link to it with http://www.example.com/mypage.html?a=1&b=2#commentform
Perhaps I used the wrong name for the type of anchor.
OK, just checked out the w3.org page on Links in HTML. (http://www.w3.org/TR/REC-html40/stru....html#h-12.1.1) They're called destination anchors, and you can do it with either a name attribute in an anchor tag, or an id attribute in any tag. I didn't know about that second one.- A. Alfred Ayache
PHP/MySQL ZCE
-
Jan 9, 2009, 00:23 #9
- Join Date
- Sep 2005
- Location
- Sydney, NSW, Australia
- Posts
- 16,875
- Mentioned
- 25 Post(s)
- Tagged
- 1 Thread(s)
<a name=something"></a> was deprecated in favour of <tag id="something"> quite some time ago. The last browser in common use to require the <a name> instead of just an id was Netscape 4 so the need for the <a name> tag ended about 5 years ago. Even back then there were some browsers that didn't recognise that properly and so an id with the same value as the name was needed to ensure proper cross browser support.
Stephen J Chapman
javascriptexample.net, Book Reviews, follow me on Twitter
HTML Help, CSS Help, JavaScript Help, PHP/mySQL Help, blog
<input name="html5" type="text" required pattern="^$">
Bookmarks