How to window.location.hash-change the location, then run a function?

407 Views Asked by At

I have a function, say

function runSomething()
{
   alert("hello");
}

I have window.onhashchange = runSomething;
And in my code, I call window.location.hash = "#processsection"

runSomething runs, however it runs before the page does to #processsection...how can I get it to only run AFTER I am on #processsection?

1

There are 1 best solutions below

0
On BEST ANSWER

In your scenario I would probably use an if condition to check if that div or body (whichever applies) is animating aka. scrolling. Here's an untested, rough idea.

function runSomething() {        
    if ($('body').is(':animated') {
        $('body').queue(function() {
            alert("hello");
        });
    } else {
        alert("hello");
    }
}