Add target= _blank in CSS
Unfortunately, no.
In 2013, there is no way to do it with pure CSS.
Update: thanks to showdev for linking to the obsolete spec of CSS3 Hyperlinks, and yes, no browser has implemented it. So the answer still stands valid.
How to style target= _blank anchors?
Try fiddle
a[target=_blank]{ color : green}
a{ color : blue }a[target=_blank]{ color : green}
<a href="someplace.html">link1</a><a href="someplace.html" target="_blank">link2</a>
How do I add target=“_blank” to a link within a div with an specific class name?
You can use querySelectorAll() and include a CSS selector. So if your class name is link-other:
document.querySelectorAll('.link-other a') .forEach(function(elem) { elem.setAttribute('target', '_blank'); })
<div class="link-other"> <a href="http://wikipedia.com">Wikipedia</a> <a href="http://google.com">Google</a></div>
how to give target= _blank to all a tags in html
Specify a default target for all hyperlinks and forms on a page:
<head>
<base target="_blank">
</head>
source
how to add target=_blank on react
Here is my solution using replace
var content = `<a href="https://stackoverflow.com">Stack Overflow</a><a href="https://google.com">Google</a>`;
class App extends React.Component {
render(){
return (
<div
dangerouslySetInnerHTML={{
__html: content.replace(/href/g, "target='_blank' href")
}}>
</div>
)
}
}
How do I add target= _blank to a link within a specified div?
/* here are two different ways to do this */
//using jquery:
$(document).ready(function(){
$('#link_other a').attr('target', '_blank');
});
// not using jquery
window.onload = function(){
var anchors = document.getElementById('link_other').getElementsByTagName('a');
for (var i=0; i<anchors.length; i++){
anchors[i].setAttribute('target', '_blank');
}
}
// jquery is prettier. :-)
You could also add a title tag to notify the user that you are doing this, to warn them, because as has been pointed out, it's not what users expect:
$('#link_other a').attr('target', '_blank').attr('title','This link will open in a new window.');
Input button target= _blank isn't causing the link to load in a new window/tab
you will need to do it like this...
<a type="button" href="http://www.facebook.com/" value="facebook" target="_blank" class="button"></a>
and add the basic css if you want it to look like a btn.. like this
.button {
width:100px;
height:50px;
-moz-box-shadow:inset 0 1px 0 0 #fff;
-webkit-box-shadow:inset 0 1px 0 0 #fff;
box-shadow:inset 0 1px 0 0 #fff;
background:-webkit-gradient( linear, left top, left bottom, color-stop(0.05, #ffffff), color-stop(1, #d1d1d1) );
background:-moz-linear-gradient( center top, #ffffff 5%, #d1d1d1 100% );
filter:progid:DXImageTransform.Microsoft.gradient(startColorstr='#ffffff', endColorstr='#d1d1d1');
background-color:#fff;
-moz-border-radius:6px;
-webkit-border-radius:6px;
border-radius:6px;
border:1px solid #dcdcdc;
display:inline-block;
color:#777;
font-family:Helvetica;
font-size:15px;
font-weight:700;
padding:6px 24px;
text-decoration:none;
text-shadow:1px 1px 0 #fff
}
.button:hover {
background:-webkit-gradient( linear, left top, left bottom, color-stop(0.05, #d1d1d1), color-stop(1, #ffffff) );
background:-moz-linear-gradient( center top, #d1d1d1 5%, #ffffff 100% );
filter:progid:DXImageTransform.Microsoft.gradient(startColorstr='#d1d1d1', endColorstr='#ffffff');
background-color:#d1d1d1
}
.button:active {
position:relative;
top:1px
}
target works only with href tags..
jQuery add target= _blank for outgoing link
assuming that all external links will start with http:// you could do this:
$('a[href^="http://"]').not('a[href*=gusdecool]').attr('target','_blank');
Related Topics
How to Make Div's Percentage Width Relative to Parent Div and Not Viewport
Paying for Multiple Items (At Once) via Paypal
Access Control Allow Origin Issue in Angular 2
Html-Tooltip Position Relative to Mouse Pointer
CSS Select Elements with Partial Id
Linking to CSS in an Svg Embedded by an Img Tag
Equalize the Height of Left and Right Div, Prevent Right Div from Going Below Left Div
Sending HTML Mail Using a Shell Script
Why Would Margin Not Be Contained by Parent Element
How to View an HTML File in the Browser with Visual Studio Code
Is It Alright to Use Multiple H1 Tags on the Same Page, But Style Them Differently
All Widths Set to Width of Widest Element
Center HTML Input Text Field Placeholder