简体   繁体   中英

How can I open a link in a new tab when the user clicks it

I Would prefer not to use javascript if that's possible but a jquery solution would be fine too. I'd appreciate any help.

I think this entirely depends on the user preferences in a browser .

You can set the target attribute for a hyperlink to be _blank . Like

<a href="someurl" target="_blank">Click me</a>

But this also depends on the user settings in a browser, whether to open this in a new window or tab.

<a href="url" target="_blank"> Click here </a> - Should open it in a new blank tab.

Only thing here is that target="_blank" has been deprecated by W3C - which generally means it's up to the users preferences in the browser.

Here is an example of using javascript - if you really need to check against the W3C validator.

target="_blank" is what can be used. There is no HTML spec item to specify opening in a tab vs in a new window.

http://dev.w3.org/html5/spec/browsers.html#valid-browsing-context-name-or-keyword

[for _blank ] a new browsing context is being requested, and what happens depends on the user agent's configuration and/or abilities

related: How can I open a new tab or window when a link is clicked?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM