Note that there are some explanatory texts on larger screens.

plurals
  1. POPrevent/stop auto anchor link from occurring
    primarykey
    data
    text
    <p>I need to prevent the automatic scroll-to behavior in the browser when using link.html#idX and &lt;div id="idX"/&gt;.</p> <p>The problem I am trying to solve is where I'm trying to do a custom scroll-to functionality on page load by detecting the anchor in the url, but so far have not been able to prevent the automatic scrolling functionality (specifically in Firefox).</p> <p>Any ideas? I have tried preventDefault() on the $(window).load() handler, which did not seem to work.</p> <p>Let me reiterate this is for links that are not clicked within the page that scrolls; it is for links that scroll on page load. Think of clicking on a link from another website with an #anchor in the link. What prevents that autoscroll to the id?</p> <p>Everyone understand I'm not looking for a workaround; I need to know if (and how) it's possible to prevent autoscrolling to #anchors on page load.</p> <hr> <h2><strong>NOTE</strong></h2> <p>This isn't <em>really</em> an answer to the question, just a simple race-condition-style kluge.</p> <p>Use jQuery's scrollTo plugin to scroll back to the top of the page, then reanimate the scroll using something custom. If the browser/computer is quick enough, there's no "flash" on the page.</p> <p>I feel dirty just suggesting this...</p> <pre><code>$(document).ready(function(){ // fix the url#id scrollto "effect" (that can't be // aborted apparently in FF), by scrolling back // to the top of the page. $.scrollTo('body',0); otherAnimateStuffHappensNow(); }); </code></pre> <p>Credit goes to <a href="https://stackoverflow.com/users/22419/wombleton">wombleton</a> for pointing it out. Thanks!</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload