Open pdf in new tab with right click option ' open in new tab'

94 views Asked by At
function showPDF(pdfUrl) {
  var iframe = document.getElementById("pdfFrame");
  iframe.style.display = "block";
  iframe.src = pdfUrl;
  document.getElementById("fullscreenButton").style.display = "block";

  iframe.scrollIntoView({
    behavior: 'smooth',
    block: 'start',
  });
}

function openNewWindow() {
  var iframe = document.getElementById("pdfFrame");
  var pdfUrl = iframe.src;
  window.open(pdfUrl, '_blank');
}

pdf links are in the list with name pdfList.

<a class="pdf-link" href="#" onclick="showPDF('https://www.africau.edu/images/default/sample.pdf')">pdf</a>

when i right click and open in new tab it opens the same page not the pdflink

1

There are 1 answers

4
Prog Ram On

Remove the script and let the browser handle it as it is supposed to.

Now you can left click to open in new tab and right-click to do whatever else you want (including open in a new tab)

<a class="pdf-link" href="https://www.africau.edu/images/default/sample.pdf" target="_blank">Open PDF in New Tab</a>