Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Overriding history.pushState leads to error in opera 11

I'm injecting the following code into a webpage via a greasemonkey script/opera extension to trap the history.pushState command, so I can do some processing whenever it's fired and still allow the pushState command to continue afterwards.

(function(history){
  var pushState = history.pushState;
  history.pushState = function(state) {
       if (typeof history.onpushstate == "function") {
          history.onpushstate({state: state});
        }
        alert('pushstate called')
        return pushState.apply(history, arguments);
  }
})(window.history);

the code works fine in FF4 and Chrome, but in Opera 11, I get the following error, if the page calls a history.replaceState command:

Uncaught exception: TypeError: 'window.history.replaceState' is not a function

Does anyone know how I can fix the above code to work with Opera as well as Chrome and Firefox?

like image 888
user280109 Avatar asked Jan 25 '11 12:01

user280109


1 Answers

In Opera 11.00, Revision 1156, the history API supported are these

>>> history.
back, current, forward, go, length, navigationMode

The full HTML5 history API is not yet covered by Opera 11.00. In general if you would like to discover, explore what is supported, you can easily use the console mode of dragonfly, the Web developer tool.

like image 112
karlcow Avatar answered Sep 24 '22 01:09

karlcow