Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

88
Views
content only appears if print is called twice javascript

I'm currently trying be able to print something to the screen using javascript. Right now, I've got a simple print function set up like below that gets triggered on a link press in HTML.

   function print() {
        console.log(printImgURL);
        let w = window.open();
        w.document.write(`<img src="${printImgURL}">`);
        w.focus();
        w.print();
        w.close();
    }
<a id="printButton" onclick="print()"title="Print"></a>

The content only appears when the link is pressed the second time (and any other time after), Although the console.log statement shows the proper URL to the image regardless if the image actually appears in the print dialogue or not. Does anyone have any idea why the content wouldn't be showing up the first the link is pressed?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Add href="#" in the anchor tag.

Example:

<a id="printButton" onclick="print()" title="Print" href="#"></a>
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!