fix javascript error when switching tab