Added onpopstate support

Now the script works properly when a user uses Back or Forward browser
buttons (as well as swipes on mobile).