Aside from using history.length in JavaScript, you can also manipulate the window's name.
For example, by checking if the window has a name when it loads... it should be empty upon first load. If you then assign "foo" to it, on subsequent loads within that same window, the window's name property will return as "foo". Unless, of course, you open a link in a new tab or window, in which case the new window should not have a name assigned to it.
(unless, of course, you open a popup using window.open(url, name, features); where you can set the name beforehand)
<script>
if(window.name == ''){
//first load (or Nth load in a new Tab/Window)
if(!SOME_VALUE_SET_FOR_2ND_TO_NTH_LOADS){
//set name so we can catch new Tab/Window
window.name = 'myWinName';
} else {
//we have a new Tab/Window (or something funky)
alert('What?! One window not cool enough for ya?\n' +
'Calling the InterWeb Police!');
}
} else if(window.name == 'myWinName'){
//2nd-Nth load
document.title = 'All is well... we think';
}
</script>
Keep in mind:
- If your page initially loads in a window/frame that already had a name, things may behave unexpectedly
- If your page contains named iframes with links targeted into them, there is a bug in IE7/8 where opening these links in a new tab/window will cause the new tab/window to inherit the name of the original iframe targeted (an odd bug with no expected fix).