Dealing with tabindex issues

Using the tab key to jump between navigation points on a page is unreliable and strange behavior occurs. One symptom is when you tab to an anchor link, the browser follows the link when you don't want it to.

The Chrome browser seems to be the culprit. Firefox seems to behave better. My solution is to test to see which key is pressed before enacting any action. Here's the events in the HTML:

<div id="back" onclick="goBack()" onkeydown="goBackifreturn()" tabindex="0">

Here's the Javascript function that tests to see if the return key (13) was pressed. You can allow other keys as well, of course.

function goBackifreturn() {
        if (event.which == 13) { goBack(); }
}

The goBack() function will close the window if the document.referrer indicated that the user got here by clicking a link to this page on Facebook. Otherwise, the browser history should take us back to the previous page.

function goBack() {
	if (document.referrer.search("facebook.com") > 0) {
		window.close();
	} else {
		window.history.go(-1);
	}
}

This seems to have fixed the problem.