Forum Moderators: open

Message Too Old, No Replies

Moving to a section of the page with a named anchor

Does it work if your url has a query string

         

chris_f

11:14 am on Dec 22, 2002 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi All,

I have a section on one of my sites where users can leave comments about an article. After they place a comment (or update their comment) they are redirected to where it is on the page. Next to their comment I have

<a name="commentxx"></a>

Where xx is the message number

in the code.

After they add on update the url they are redirected to is

http://domain.com/article.asp?t=yyyy#commentxx

Where xx is the comment id (the same as above) and yyyy is the article id

The problem is, it does not scroll to the comment. The page loads as normal with the user placed at the top of the page. The only thing I can think of is that it doesn't work with querystrings in the url.

Is this the case? If not, can anyone see what is going wrong?

Chris

Nick_W

11:17 am on Dec 22, 2002 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You need to use id="blah" Chris, not name.

Nick

chris_f

11:22 am on Dec 22, 2002 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I'll try that Nick.

Thanks.
Chris.

p.s. How does Brett get it to work? He uses name

chris_f

11:24 am on Dec 22, 2002 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



ID and NAME produce the same result.

Chris

Nick_W

11:28 am on Dec 22, 2002 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Yeah, you're right. I think it must be the query string. Have you tried without the string?

Nick

chris_f

11:36 am on Dec 22, 2002 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Can't seem to get it working still.

Gggrrrrr.

Chris
Head beginning to hurt

chris_f

11:43 am on Dec 22, 2002 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Could it be a localhost thing?

chris_f

11:59 am on Dec 22, 2002 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



It's a browser thing.

IE6 - No scrolling
NN6.2.3 - Scrolls a little (nowhere near the tag though)
Opera7 - BINGO. Works a treat.

Why? WebmasterWorld works in IE6 so why doesn't my code?

I'm missing something.

Chris

head spinning now

ikbenhet1

12:08 pm on Dec 22, 2002 (gmt 0)

10+ Year Member




<a name="thing">

<a href="#thing">thing</a>

This works in ie6. is this the way you did it?

--> i've tried just about everything with #, i works fine even if i pass variables throug the adres bar or make it complex.

could it be the .asp extension?

SuzyUK

12:57 pm on Dec 22, 2002 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member




[domain.com...]
Where xx is the comment id (the same as above) and yyyy is the article id

I think it should be like this:
[domain.com...]

i.e. bookmark straight after page name then then querystring

Suzy

chris_f

2:08 pm on Dec 22, 2002 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



SuzyUK,

I've tried you code. The Querystring cannot be read if the put the anchor before the querystring. I get a 500.100 error

Chris

korkus2000

2:12 pm on Dec 22, 2002 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Have you tried an & or a? right before the #? I remember somewhere that this was a hack. I don't know if it is for your problem.

chris_f

2:22 pm on Dec 22, 2002 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



At current my URL is:

/article.asp#comment24?t=1

korkus2000

2:27 pm on Dec 22, 2002 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



try
article.asp?t=1&#comment24

Worth a shot

SuzyUK

2:28 pm on Dec 22, 2002 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi chris_f

Yes you're right I'm sorry, I just remebered having the same problem and this was one of the things I triad at the time

however I have now tested it and your original format is correct and it's working crossbrowser for me..

However in my test I caused it not to work by not having the quotes in the script correct

You might want to check that? when you hover over the link is the status bar showing you the correct link address including the bookmark?

or post the line of code that's generating the URL and bookmark, Maybe there's an error in it?

Sorry for misinformation before..

Suzy

chris_f

2:41 pm on Dec 22, 2002 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



My URL is back to: ...../article.asp?t=1#msg88

The anchor text is <a name="msg88"></a>

Browser test remain the same
IE6 - Nothing
NN6.2.3 - Slight movement to the first piece of anchor text (not the correct anchor text)
Opera7 - Works fine

Chris

SuzyUK

2:52 pm on Dec 22, 2002 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi chris...

I meant the ASP code (sorry I know this isn't the right board)

code should be like this:
response.write "<a href=""articles.asp?id=" & objRS("ArtID") & "#msg" & objRS("msgID") & """>"

I got all confused with my quotation marks at the end....
:) and that's what was causing my error and I wondered if it's the same for your links?

Suzy

ikbenhet1

3:05 pm on Dec 22, 2002 (gmt 0)

10+ Year Member



remove the </a>

chris_f

3:18 pm on Dec 22, 2002 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



removing the </a> does nothing (except confuse the browser).

chris_f

3:25 pm on Dec 22, 2002 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I've just looked at some code that I have written before that works.

Indentical to what I have written.

ggggggggrrrrrrrrrrrrrrrrrrrrrrrrrr

Chris

korkus2000

3:26 pm on Dec 22, 2002 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I think your problem is a side effect of something else on the page. What you have should work. Have you validated the page?

chris_f

3:40 pm on Dec 22, 2002 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Yep.

I've just placed an anchor at the bottom and that fails to work. I'll try again tuesday. Fresh perspective and all that.

Thanks to all who tried.
Chris.

dingman

6:16 pm on Dec 22, 2002 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



For a bit of encouragement, I've got code that does the same thing and works in everything I've tested in. (ie5.5, ie6, Mozilla (assorted versions & derivatives), Opera 6, Opera 7)

defanjos

6:59 pm on Dec 22, 2002 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



chris,

I think if you use session variables it will work. Do something like the code below at the top of your page - you probably have to modify it a bit.
Note: Simply call session("t") and session("message") on your SQL code (if you need to), instead of request("t") and request("messagenumber"), also, in the body write the anchor as <a name="<%=session("anchor")%>"></a>

<%
if request("messagenumber")<>"" then
Dim anchor
anchor = "comment" & request("messagenumber")
session("t") = request("t")
session("anchor" )= anchor
session("message" )= request("messagenumber")
response.redirect "article.asp" & "#" & anchor
end if
%>

good luck