Snap to top of page...

H

heizer1

Hello,
I have not done much javascripting so this might be really easy. I have
a page that has anchors in it and I want to force that page to always
snap to the top instead of to the position when someone clicks on the
href to takethem to the anchor.

Thanks,
- Charles
 
A

ASM

(e-mail address removed) a écrit :
Hello,
I have not done much javascripting so this might be really easy. I have
a page that has anchors in it and I want to force that page to always
snap to the top instead of to the position when someone clicks on the
href to takethem to the anchor.


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

<a href="#anAnchor"
onclick="location='#';return false;">false anchor</a>
 
H

heizer1

Thanks,
I did find what I was looking for. Since I don't know JS very well I
was not sure how to put it. Anyways, I added
onfocus="window.scrollTo(0,0);" to my body tag and everything is now
working.

- Charles
 
T

Thomas 'PointedEars' Lahn

I did find what I was looking for. Since I don't know JS very well I
was not sure how to put it. Anyways, I added
onfocus="window.scrollTo(0,0);" to my body tag and everything is now
working.

For suitable values of "to work".

- It will break with a runtime error (ReferenceError or TypeError) where
client-side scripting, but not this proprietary method, is supported.[1]

- It is not Valid markup, and will silently fail where this proprietary
attribute is not supported.[2]

- It will be an annoyance for the rest of the users.[3]

Why don't you go snowboarding instead?


PointedEars
___________
[1]
<URL:http://developer.mozilla.org/en/docs/DOM_Client_Object_Cross-Reference:window>
<URL:http://developer.mozilla.org/en/docs/DOM:window.scrollTo>

<URL:http://msdn.microsoft.com/workshop/author/dhtml/reference/methods/scrollto.asp>
[2] <URL:http://validator.w3.org/>
<URL:http://www.w3.org/TR/html4/index/attributes.html>
[3] <URL:http://codestyle.org.uk/javascript/FAQ.shtml#suppressctrln>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,436
Messages
2,571,696
Members
48,796
Latest member
Greg L.
Top