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
  • 756,363
  • 169
  • 1,062
  • 1,111
GregM
  • 3,450
  • 3
  • 33
  • 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,522
  • 14
  • 71
  • 107