Skip to content

Instantly share code, notes, and snippets.

@allanesquina
Last active August 29, 2015 14:06
Show Gist options
  • Save allanesquina/0d7e35e200a67156e9b1 to your computer and use it in GitHub Desktop.
Save allanesquina/0d7e35e200a67156e9b1 to your computer and use it in GitHub Desktop.
onpopstate equivalent
// dep: jQuery
//armazena state
var __old = history.state;
// checa state
setInterval( function() {
if( history.state !== __old ) {
//triga o evento
$( window ).trigger( 'meuevento', [1,3,2] );
// cacheia state atual
__old = history.state;
}
}, 100);
// Evento a ser disparado
$( window ).on( 'meuevento', function( e ) {
console.log( 'disparou ', arguments );
})
// Simula alguns pushstats
var stateObj = { foo: "bar1" };
history.pushState( stateObj, "page 2", "http://localhost/teste" );
stateObj = { foo: "bar2" };
history.pushState( stateObj, "page 3", "http://localhost/teste2" );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment