Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialDaniel Scalia
8,546 PointsHow do you generate a hyperlink that browser opens another window, so visitors doesn't necessarily leaves your site?
Sometimes I want a hyperlink from one page to another page on my site. Sometimes, I want the hyperlink to open up another window that leads visitor to another site. How can you control whether the hyperlink opens a new window or uses the same window?
3 Answers
Mikkel Rasmussen
31,772 Points <a href="#" target="_blank">Link</a>
You can read more about target here link
Jonathan Grieve
Treehouse Moderator 91,253 PointsHi Daniel,
You can use a target attribute in each anchor element to achieve this.
To make the browser open a new tab you do something like this.
<a href="#" target="blank">Link text</a>
Good luck :)
Mikkel Rasmussen
31,772 PointsYou forgot about the _ symbol.
Daniel Scalia
8,546 PointsThanks a bunch! Very helpful.
Jonathan Grieve
Treehouse Moderator 91,253 PointsHaving tested in Chrome Dev tools, it worked without adding the preceding _ underscore. :-)
Immanuel Jaeggi
5,164 PointsAs a matter of practice, you should always write the attribute like so:
target="_blank"
Some people may have older browsers that may not recognize this piece of code. Better to begin learning the correct way and then make allowances for shortcuts when you are confident of the results.
Marcus Sassi
4,394 PointsYou'll need to use target="_blank"
it is the _blank
that opens up a new window.
example.
<a href="teamtreehouse.com" target="_blank">Learn how to code</a>
Daniel Scalia
8,546 PointsDaniel Scalia
8,546 PointsThanks a bunch! Very helpful.