• Jobs
  • About Us
  • professionals
    • Home
    • Jobs
    • Courses and challenges
  • business
    • Home
    • Post vacancy
    • Our process
    • Pricing
    • Assessments
    • Payroll
    • Blog
    • Sales
    • Salary Calculator

0

112
Views
Hide Google Ads while printing the page

I am trying to use window.print to print a single image on my page.

That's the image user is interested to print.

Before putting ads on my website everything was working fine but after starting adsense ads while printing the page the print preview page shows the ads too.

How can i hide them ?

before i hide all the elements by css code which looks like below but now as i won't be able to know how and where an ad is placed as ad is auto.

@media print {
    @page {
        margin: 0;
        margin-top: 10px;
    }
    nav, header, .cardButtonRow, #about, .toastContainer, footer, .adsbygoogle, .google-auto-placed {
        display: none;
    }
    .cardImage img {
        width: 82%;
        box-shadow: none;
    }
} 

The page structre mostly

<body>
<nav>....</nav>
<article class="container cardContainer">


        <header>
            <h1>Your eCard is Ready to Print</h1>
            <p>Save it or Print it !</p>
        </header>

        <div class="cardImage">
            <img alt="">
        </div>

        <div class="cardButtonRow">
            <a class="button" onclick="printClick();">Print Card</a>
            <a class="button">Download</a>
        </div>

...
<footer>...</footer>
</body> 

How to print only the image ?

almost 3 years ago · Juan Pablo Isaza
1 answers
Answer question

0

How about something like this:

@media print {
    @page {
        margin: 0;
        margin-top: 10px;
    }
    * {
        display: none !important;
    }
    html, body, article, .cardImage, .cardImage img {
        display: block !important;
    }
    .cardImage img {
        width: 82%;
        box-shadow: none;
    }
}

Hide everything, then un-hide the image and its ancestors.

almost 3 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 Our process Sales
Legal
Terms and conditions Privacy policy
© 2025 PeakU Inc. All Rights Reserved.

Andres GPT

Recommend me some offers
I have an error