How can I bump my user back to the top of the screen?

Bruce Gust
Bruce Gust used Ask the Experts™
on
Head out to http://brucegust.com/kitchen/sidebar_toggle.php. Click on the button that says "select options." When you do that, you get a little popup in the center of the screen. Click on the "add to cart" button and a sidebar appears from the right. If you scroll up, you'll see a line of text that reads "where am I." If you click on that, the sidebar disappears.

What I need to happen is that the screen needs to jump to the top so the "where am I" text can be read without having to scroll to the top.

How can I do that?
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Web Programmer/Technician
Commented:
I assume you want javascript code to do this? This should work:
window.location.href="#";

Open in new window

If you wanted to scroll to a specific element on the page, you should follow the hash mark with the id of the element you wish to scroll to. Without an id, the hash mark will simply take you to the top of the page.

For example, the following would scroll to the top of the div with id "sidebar_wrapper".
window.location.href="#sidebar_wrapper";

Open in new window

Bruce GustPHP Developer

Author

Commented:
xmediaman!

Thanks for the feedback! I wound up using "window.scrollTo(0, 0);" and it worked great! I will keep your information handy for future endeavors, however. Thanks again for weighing in!
Bruce GustPHP Developer

Author

Commented:
Also, I've got another question at http://www.experts-exchange.com/questions/28932142/Why-does-my-sidebar-close-after-this-toggleClass.html. Would love your expertise on that one.

Thanks!

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial