I would not use window.close(). Your game is a guest in the player's browser, be a good one. Attempting to close tabs/windows without permission is not how you go about that.
If you really want to kick the player to the curb on a bad end, then I'd suggest calling the Engine.restart() static method instead. The code might look like:
<<remember $BADEND to true>>
<<script>>Engine.restart();<</script>>
To redirect the player to the bad end passage on startup, I recommend the Config.navigation.override setting, not a <<goto>> in your starting passage. For example: (goes in Story JavaScript)
Config.navigation.override = function () {
if (State.variables.BADEND) {
return 'you meet a terrible fate';
}
};
To remove the bad end hijack for the player at some point, do something like the following:
<<forget $BADEND>>