Remove use of indexOf which isn't available on IE8.

Also try and improve disconnect behaviour when navigating away.