JSFiddle - React, Tailwind, and code Playground

by kein1945

HTML

<a href="http://example.com">
  Hrere link for exmaple.com but here is <strong>https://jsfiddle.net/</strong>
</a>

JavaScript

const s = document.getElementsByTagName('strong')[0];
s.addEventListener('click', function(e) {
	e.preventDefault();
	e.stopPropagation();
  goTo(e, this.innerHTML)
})

function goTo(e, url) {
	const isWheelClick = 2 === e.which;
  const isCtrlClick = (1 === e.which) && e.ctrlKey;
	if (isWheelClick || isCtrlClick) {
  	externalOpen(url)
  } else {
  	localOpen(url)
  }
}

function externalOpen(url) {
	window.open(url)
}
function localOpen(url) {
  document.location.href = url;
}