Asked 8 years ago
17 Nov 2016
Views 1726
css-learner

css-learner posted

<A> link should open in new tab in HTML

i am using <A> link in html


<a href="www.open-in-new-tab.com"></a>


its afiliate link and should be open in new tab so current page remain same

is it possible <a> link open in new tab by Javascript Or Css Or Html ? anyhow . suggest something
Mitul Dabhi

Mitul Dabhi
answered Nov 30 '-1 00:00

if you seeking window new tab for only some specific type of doc not for all link than
jQuery.exLink
is one plugin in jQuery which can help you on this .

usage



<script type="text/javascript" src="/exLink/jquery.exLink.js"></script>

<link rel="stylesheet" href="/exLink/jquery.exLink.css">
exLink.init();

exLink provide automate detection to a href link and if they have following format to download it open in new tab
filetypes: 'pdf', 'xls', 'docx', 'doc', 'ppt', 'pptx'

i did not use it but it seems good
shyam

shyam
answered Nov 30 '-1 00:00

how to make all link open new tab by jQuery ?

$(a).click(function(){
var href=$(this).attr("href"); 
 event.preventDefault();
 window.open(href, '_blank');
});

above code use jQuery . each a href click goes to new tab

specific selected link only open in new tab


$(".newtab").click(function(){
var href=$(this).attr("href"); 
 event.preventDefault();
 window.open(href, '_blank');
});


apply newtab class to <a> which you want to open in new tab
ravi

ravi
answered Nov 30 '-1 00:00

its very easy to make it link to open in new tab
use target="_blank" at <a> link


<a href="www.open-in-new-tab.com" target="_blank" ></a>


Rasi

Rasi
answered Nov 30 '-1 00:00

one can use window.open from core JavaScript which used to create new window or tab at browser


var windowObjectReference;
var strWindowFeatures = "menubar=yes,location=yes,resizable=yes,scrollbars=yes,status=yes";

function openNewTab(url,windowname) {
  windowObjectReference = window.open(url,windowname strWindowFeatures);
}



 <a href="google.com" onclick="openNewTab('google.com','Google')" >New Window</a>
Post Answer