I tried many variations to put target="_blank"
in links with jQuery, but I can't get it to work.
Here's my code:
var thumbfile = "<?php echo $smit_iturl_v; ?>"; jQuery(document).ready(function () { var actualHost = jQuery.trim(jQuery.url.attr("host")); jQuery("a img").each(function (i) { if (jQuery.trim(jQuery.url.setUrl(jQuery(this).attr("src")).attr("host")) == actualHost && (jQuery.url.setUrl(jQuery(this).attr("src")).attr("path")).indexOf("wp-content") != -1 && isImage(jQuery.url.setUrl(jQuery(this).attr("src")).attr("file"))) { var parentTag = jQuery(this).parent().get(0).tagName; parentTag = parentTag.toLowerCase(); if (parentTag == "a" && jQuery.url.setUrl(jQuery(this).parent().attr("href")).attr("host") == actualHost && jQuery.url.setUrl(jQuery(this).parent().attr("href")).attr("path").indexOf("wp-content") != -1 && isImage(jQuery(this).parent().attr("href"))) { var description = (jQuery(this).attr("alt") == "") ? jQuery(this).attr("title") : jQuery(this).attr("alt"); jQuery(this).parent().attr("href", thumbfile + "?title=" + jQuery(this).attr("title") + "&description=" + description + "&url=" + stripDomain(jQuery(this).parent().attr("href")) ); } } });
How can I do it?
Conclusion. You can use the target="_blank" attribute if you want your users to click on a link that opens up a new browser tab. The target="_blank" attribute is used inside the opening anchor tag like this.
Unfortunately, no. In 2013, there is no way to do it with pure CSS.
target="_blank" is a special keyword that will open links in a new tab every time. target="blank" will open the first-clicked link in a new tab, but any future links that share target="blank" will open in that same newly-opened tab.
The HTML target attribute defines where the linked document will open when the user clicked on the link. If target=”_blank” is set with anchor element, then the linked document will open in a new tab otherwise document is open in the same tab.
Too much information! This should work fine:
$("a").attr("target","_blank");
See the example here http://jsbin.com/evexi/edit. It works perfectly.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With