1

How do I call a javascript function every time the URL has a change with the string after the hash?

for example .com/onepage/

(onwindowload called)

.com/#1000

(need a function to be called)

.com/#500

(need a function to be called)

Felix Kling
  • 795,719
  • 175
  • 1,089
  • 1,143
GregM
  • 3,624
  • 3
  • 35
  • 51

1 Answers1

1

Here is a way......

window.location.watch(
    'hash',
    function(id,oldVal,newVal){
        console.log(oldval+" to "+newVal);
        //Do something.........
    }
);
AtanuCSE
  • 8,832
  • 14
  • 74
  • 112