views:

593

answers:

3

Hello,

is there a way to delay the "jump" to an anchor tag on page load using ASP.NET and jQuery?

Actual problem is that i have a jQuery-function that on page load hides all divs of a certain class. Now, when i have an anchor tag in the middle of the page, and link to that anchor, when the page loads the "anchor jump" happens before jQuery has a chance to hide the divs -> user goes to completely wrong part of the page.

greets, J.Arola

A: 

Maybe you could set the location's fragment to an empty string and store the old value upon page load, then reset location's fragment when all's done.

ASP.Net probably can't help because the fragment won't be sent to the server.

Alan
A: 

If you control the incoming links, you could replace the #hash suffix with a ?query suffix. That will be ignored by the browser, but is accessible to JavaScript in location.search. You can then do the scroll yourself in JavaScript, after hiding your divs.

RichieHindle
+2  A: 

Why do you use jQuery to hide the divs? Just use a style instead, and the divs are hidden from start:

<style type="text/css">
.TheClassToHide { display: none; }
</style>
Guffa
Wow, that's a great question indeed. This worked like a charm.
juarola