views:

42

answers:

1

I am using asp.net mvc with ajax navigation. I use jquery address and I can change the address bar to be like "MYPage.Com/#/Url", but how can I invoke my route when the user enters that link?

This has probably been asked before but I could not find it, so please point me to it if you find it.

A: 

There is no event for that (at least not the last time I've checked). You need to make a checker function in JS that will run once every 100ms for example (or more often).

var currentHash="";
function CheckHash()
{
    if(currentHash!=window.location.hash)
    {
        currentHash=window.location.hash;
        NavigateTo(currentHash); //or whatever code to execute when address behind `#` changes
    }
}

CheckHash(); //Initial Run, for fast reaction on load
window.setInterval(CheckHash,100); //schedules the function to run once every 100ms
Alexander
Thanks, but look at this link, they don't seem to have a timer http://www.asual.com/jquery/address/samples/tabs/
Oskar Kjellin
There is a timer inside the plugin which is used only for older versions of Firefox, Safari and Opera.
Rostislav