[ACCEPTED]-Is it alright to use target="_blank" in HTML5?-window
It looks like
target="_blank" is still alright. It is listed 1 as a browsing context keyword in the latest HTML5 draft.
It is ok to use
target="_blank"; This was done away with 7 in XHTML because targeting new windows will 6 always bring up the pop-up alert in most 5 browsers. XHTML will always show an error 4 with the target attribute in a validate.
HTML 3 5 brought it back because we still use it. It's 2 our friend and we can't let go.
Never let 1 go.
target="_blank" is acceptable in HTML5, I personally try never 42 to use it (even for opening PDFs in a new 41 window).
HTML should define meaning and content. Ask yourself, “would the meaning of the
a element change if the
target attribute were removed?” If 40 not, the code should not go in the HTML. (Actually 39 I’m surprised the W3C kept it… I guess they 38 really just can’t let go.)
That being 28 said, neither of these is the right answer. Out there somewhere is the opinion that how a link opens should ultimately be decided by the end user. Take this example.
You’re surfing 27 Wikipedia, getting deeper and deeper into 26 a rabbit hole. You come across a link in 25 your reading.
Let’s say you want to skim 24 the linked page real quick before coming 23 back. You might open it in a new tab, and 22 then close it when you’re done (because 21 hitting the ‘back’ button and waiting for 20 page reload takes too long). Or, what if 19 it looks interesting and you want to save 18 it for later? Maybe you should open it in 17 a new background tab instead, and keep reading 16 the current page. Or, maybe you decide you’re 15 done reading this page, so you’ll just follow 14 the link in the current tab.
The point is, you 13 have your own workflow, and you’d like your 12 browser to behave accordingly. You might 11 get pretty frustrated if it made these kinds 10 of decisions for you.
THAT being said, web 9 developers should make it absolutely clear 8 where their links go, what types and/or 7 formats of sources they reference, and what 6 they do. Tooltips can be your friend (unless 5 you're using a tablet or phone; in that 4 case, specify these on the mobile site). We 3 all know how much it sucks to be taken somewhere 2 we weren't expecting or make something happen 1 we didn't mean to.
it's by the easiest way to open a new window 8 for something like a PDF
It's also the easiest 7 way to annoy non-Windows users. PDF open 6 just fine in browsers on other platforms. Opening 5 a new window also messes up the navigation 4 history and complicates matter on smaller 3 platforms like smartphones.
Do NOT open new 2 windows for things like PDF just because 1 older versions of Windows were broken.
Most web developers use
target="_blank" only to open links 7 in new tab. If you use
target="_blank" only to open links 6 in a new tab, then it is vulnerable to an 5 attacker. When you open a link in a new 4 tab (
target="_blank" ), the page that opens in a new tab 3 can access the initial tab and change its 2 location using the
rel="nofollow noopener noreferrer"
While target is still acceptable in HTML5 9 it is not preferred. To link to a PDF file 8 use the download attribute instead of the target 7 attribute.
Here is an example:
<a href="files/invoice.pdf" download>Invoice</a>
If the original 6 file name is coded for unique file storage 5 you can specify a user-friendly download 4 name by assigning a value to the download 3 attribute:
<a href="files/j24oHPqJiUR2ftK0oeNH.pdf" download="invoice.pdf">Invoice</a>
Keep in mind that while most modern 2 browsers support this feature some may not. See 1 caniuse.com for more info.
I think target attribute is deprecated for 2 the
<link> element, not
<a>, that's probably why 1 you heard it's not supposed to be used anymore.
More Related questions