Jquery hash set function

138 Views Asked by At

I need to call a function whenever this line is executed

window.location.hash = "#globalSearchView";

Currently I'm using hash change function

$(window).on("hashchange",function(e) {
    var hash = window.location.hash;
    switchtabs(hash);
});

It works only in case when hash is changed but doesn't work when same hash. I want to call a function switchtabs whenever this line

window.location.hash = "#whatever";

is executed no matter same hash or different. thanks

1

There are 1 best solutions below

1
Brian Patterson On

Maybe this?

var l = location.prototype;
Object.defineProperty(l, 'hash', {
  get: function() { return this.hash; },
  set: function(t) { this.hash = t; switchtabs(t); }
});