Meta Question

mirza's avatar

How do I get a link to open in a new tab?

Asked by mirza (5057points) 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

sferik's avatar

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.

mirza's avatar

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

sferik's avatar

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?

mirza's avatar

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

mirza's avatar

this is the closest i can get to a new tab

mirza's avatar

oops fluther blocks javascripts but heres the code
<*a href="" 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)

zain's avatar

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.

glial's avatar

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

mirza's avatar

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

sferik's avatar

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).

zacko's avatar

"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!

Vincentt's avatar

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?).

swimmindude2496's avatar

Just right click

aidje's avatar

As I user, if I want a link to open in a new tab, I’ll open it in a new tab. target=“_blank” is super annoying.

Vincentt's avatar

@aidje – totally agree :)

swimmindude2496's avatar

Or just control click in Windows.

Answer this question




to answer.
Your answer will be saved while you login or join.

Have a question? Ask Fluther!

What do you know more about?
Knowledge Networking @ Fluther