Create a W3C Validated Anchor Link with Target="_Blank"

w3c validation for target blank

target=_blank is perfectly valid HTML5. Try the below HTML document in the W3 Validator

<!doctype html>
<head><title>blank</title></head>
<body><p>A link to <a href="http://example.com" target="_blank">Example</a>...</body>

XHTML Strict 1.0 - target=_blank not valid?

You might want to check out the W3 Frequently Asked Questions: http://www.w3.org/MarkUp/2004/xhtml-faq#target

Why was the target attribute removed from XHTML 1.1?

It wasn't. XHTML 1.0 comes in three versions: strict, transitional, and frameset. All three of these were deliberately kept as close as possible to HTML 4.01 as XML would allow. XHTML 1.1 is an updated version of XHTML 1.0 strict, and no version of HTML strict has ever included the target attribute. The other two versions, transitional and frameset, were not updated, because there was nothing to update. If you want to use the target attribute, use XHTML 1.0 transitional.

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

Is it alright to use target=_blank in HTML5?

It looks like target="_blank" is still alright. It is listed as a browsing context keyword in the latest HTML5 draft.

How to simulate target=_blank in JavaScript

<script>
window.open('http://www.example.com?ReportID=1', '_blank');
</script>

The second parameter is optional and is the name of the target window.

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');

How to add target=_blank to JavaScript window.location?

window.location sets the URL of your current window. To open a new window, you need to use window.open. This should work:

function ToKey(){
var key = document.tokey.key.value.toLowerCase();
if (key == "smk") {
window.open('http://www.smkproduction.eu5.org', '_blank');
} else {
alert("Kodi nuk është valid!");
}
}

What is the difference between target=_blank and target=blank?

blank targets an existing frame or window called "blank". A new window is created only if "blank" doesn't already exist.

_blank is a reserved name which targets a new, unnamed window.



Related Topics



Leave a reply



Submit