If a user is on your website and opens another link (also to your website) in a new tab, is it possible to differentiate this from the user just clicking on the link normally? This can be in javascript, on the server, whatever.
I'm guessing that the answer is that you cannot do this, but I wanted to double check.
You can examine the ctrlKey , shiftKey , and metaKey properties of the event object. If either is true, the key control, shift, or meta (Apple's command) key is being held and you should allow the default link action to proceed.
1) select "open link in new background tab" from the context menu (second choice), 2) use middle-click on the link with your mouse; 3) use Ctrl+leftclick on the link with your mouse, 4) designate a mouse gesture to open a background tab when you perform it over a link.
Opening an external link in a new tab allows users to explore the other site as much as they want without having to hit the back button again and again to go back to your site. All they need to do is click the tab your site is on.
You just need an anchor ( <a> ) element with three important attributes: The href attribute set to the URL of the page you want to link to. The target attribute set to _blank , which tells the browser to open the link in a new tab/window, depending on the browser's settings.
You can sort of do it like this:
if (history.length == 1) { // Um, needs to be 0 for IE, 1 for Firefox // This is a new window or a new tab. }
There may be other ways for history.length
to be 1
, but I don't know what they might be.
In addition to history.length in JavaScript you can read/write the window's name.
Thus if you check if it has a name onload... it should be blank on the very first load... if you then set it to "foo"... on each subsequent load in that window... the window.name property will return "foo"... unless you open a link in a new tab/window... that new window should have no name set.
(unless of course you open a popup via window.open(url, name, features); which allows you to pre-set the name)
<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>
Caveats:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With