How do I get a link to open in a new tab?
Asked by
mirza (
5057)
August 16th, 2007
I know some browsers dont support tabbed browsing (but only 8 percent of my visitors use IE so that doesnt matter) .
Observing members:
0
Composing members:
0
16 Answers
There's no way for you, as a developer, to force a link to open in a new tab with HTML.
You could open the link in a new window, but that has long been recognized as a bad idea. Using the TARGET
attribute with an A
element is actually deprecated as of HTML 4.01. The main idea is that the user (not the document) should have control over spawning new browser windows (or new tabs).
As a user, a good browser will allow you to always open new pages in a new tab, if that is your preference.
i know firefox lets me open my windows as new tabs
but one of my friends has a javascript enabled in his page that opens ads in new tabs - only he wont share the javascript
Can you provide a link to his page that has one of these links? I can find the code for you.
My point above was that it's not a good practice to seize this control from the user. Why do you need to open a link in a new tab, anyway?
well i tried finding the code with firebug - it just runs a javascipt file hosted on the server which shows up as newtab.js
i just dont want users to navigate away when they click on ads
but i also dont want new windows
this is the closest i can get to a new tab
ZIKED
oops fluther blocks javascripts but heres the code
<*a href="http://ziked.com" onclick="if(!event.ctrlKey&&!window.opera){alert('Please Try Again while holding down the Ctrl Key');return false;}else{return true;}" target="_blank">ZIKED
(the asterisk is just to display html on fluther)
If you navigate to the newtab.js file in your browser, you can see its contents. There is no way to hide client-side code such ad javascript from the user because, by definition, the client (browser) requires the code to execute.
As a web developer, I feel like what you want to do takes over the users control of his or her experience. Much like resizing the webpage.
Just because you want it to open in a new tab, you users may not. If you do find the means to implement this, you might want to give users a choice.
Just a thought
is there a way to add the CONTROL button's click event to a normal click event ?
because if so maybe ctrl click will result in a new tab
It's not possible to generate events external to the document in Javascript. Consider the security implications if this was possible (e.g., firing Control+Alt+Delete).
Within a document, you can use keyCode to determine what key the user presses (the keyCode for Control is 17).
"My point above was that it's not a good practice to seize this control from the user."
I agree with sferik, don't hijack the user experience, it can be very frustrating on the client end. In the old days, everyone wanted their sites to fill the screen on load, how annoying!
Really, just target=“_blank” would be fine (see points made by zacko and sferik). target=“_blank” will open in a new tab for me, because I have set it that way, and if you’ve got a bit respectable browser then you should be able to set that. In fact, this behaviour will be default for Firefox 3 (or was it already for Firefox 2?).
@aidje – totally agree :)
Or just control click in Windows.
Answer this question