How to focus without moving the scrollbar?

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
lovelf
Forum Contributor
Posts: 153
Joined: Wed Nov 05, 2008 12:06 am

How to focus without moving the scrollbar?

Post by lovelf »

Is it possible to set focus on an element without moving the scrollbar if this element is below available height ?

Code: Select all

<textarea id="rfz" style="position:absolute;bottom:-100px;"></textarea>

Code: Select all

<script type="text/javascript">
function rfz(){document.getElementById("rfz").focus();}
setTimeout(rfz,0);
</script>
User avatar
volomike
Forum Regular
Posts: 633
Joined: Wed Jan 16, 2008 9:04 am
Location: Myrtle Beach, South Carolina, USA

Re: How to focus without moving the scrollbar?

Post by volomike »

I don't think so. Let's look at this from a different angle. What is it that you are trying to do that would cause you to go down this road in the first place?
lovelf
Forum Contributor
Posts: 153
Joined: Wed Nov 05, 2008 12:06 am

Re: How to focus without moving the scrollbar?

Post by lovelf »

To use it as an incentive for people to write comments.

The comments textarea is below the articles and I would like to have focus on it but without the scrollbar going down to where the textarea is.

Thanks.
User avatar
papa
Forum Regular
Posts: 958
Joined: Wed Aug 27, 2008 3:36 am
Location: Sweden/Sthlm

Re: How to focus without moving the scrollbar?

Post by papa »

How about using an anchor (<a name>) and let people decide wether they want to write a comment or not? An easy way to make the page jump down to the comments field if the article is long.
lovelf
Forum Contributor
Posts: 153
Joined: Wed Nov 05, 2008 12:06 am

Re: How to focus without moving the scrollbar?

Post by lovelf »

Yes, when the anchor is clicked then the focus is set to the textarea.
User avatar
papa
Forum Regular
Posts: 958
Joined: Wed Aug 27, 2008 3:36 am
Location: Sweden/Sthlm

Re: How to focus without moving the scrollbar?

Post by papa »

Sounds nice.
Post Reply