I have solved this by using simple trick. It might be useful.
I have removed the target attribute dynamically based on the link. i.e if the link is undefined or empty or javascript:void(0), then we will remove the target attribute by using below code.
If the link is proper one, we will add the target attribute for that hyper link("second if condition" will do that, because in my page links are dynamic).
I have copied the sample html file(Test.html).
if we want to remove the attribute on onload of the page, copy the script code in this file and paste it at the end of your required file.
If we want to apply this for dynamic links, we have to put this code in one function and we can call it when it is required.
This code will be applicable to all the hyper links in that page. We can limit this to particular set of links by using class or any other attributes.
Test.html
---------
<script src="https://code.jquery.com/jquery-3.1.1.min.js"></script>
<a href="javascript:void(0);" target="_blank">Link1</a>
<a href="javascript:void(0);" target="_blank">Link2</a>
<a href="www.url1.com" target="_blank">Link3</a>
<a href="www.url2.com" target="_blank">Link4</a>
<script>
$("a").each(function() {
if(typeof(this.href) == 'undefined' || this.href == 'javascript:void(0);') {
$(this).attr('href', 'javascript:void(0);');
$(this).removeAttr('target');
}
if(typeof(this.href) != 'undefined' && this.href != 'javascript:void(0);') {
var s_link = this.href;
if (s_link.indexOf('http://') === -1 && s_link.indexOf('https://') === -1) {
s_link = 'https://' + s_link;
}
$(this).attr('href', s_link);
$(this).attr('target', '_blank');
}
});
</script>
javascript:void(0);
was considered bad practice. – j08691 Jun 13 '13 at 18:30