Dealing with window.close() Issues

Modern browsers do not allow the window.close() function to close a page/tab that was not created by your page. It will silently fail unless you're looking at the Javascript developer console, which will report:

Scripts may close only the windows that were opened by them.

There's little you can do about this except notify the user that the window won't be closed. In the following goBack() function, the window should be closed if we got here as a reult of a Facebook user clicking a link to this page. Otherwise, the browser should go back to the previous page, taken from the browser's history. The window.close() function will fail if the user clicks a link on the page to go elsewhere but then returns.

function goBack() {
   var x = document.referrer;
   if ("") > 0) {
      if (window.closed == false) {
         alert("Sorry, you'll have to close this browser tab yourself.");
   } else window.history.go(-1);