Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6635737
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T23:05:36+00:00 2026-05-25T23:05:36+00:00

when printing a page, the javascript code seems to be executed. how can I

  • 0

when printing a page, the javascript code seems to be executed.
how can I determine, if the page is currently being printed? I do some js-resizing, and have to handle printing a little bit different.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T23:05:36+00:00Added an answer on May 25, 2026 at 11:05 pm

    You can’t, except for IE browsers. No other browser has a before print event. You can, however, target a specific stylesheet to only apply while printing:

    <!-- In head -->
    <link rel="stylesheet" type="text/css" media="print" href="print.css" />
    

    This stylesheet will be applied before printing. This allows you to perform some amazing changes, including hiding major sections, moving items around, and performing print-only styling, such as page breaks.

    Another option is to provide the user with a “Print this Page” button. That button can handle your JavaScript, call window.print(), and revert the changes:

    function printMe() {
        // perform changes
        window.print();
        // revert changes
    }
    

    The window.print() method always blocks (in every browser I’ve tested), so it’s safe to immediately revert the changes afterward. However, if the user choose to print via the menu or toolbar, you are out of luck.

    One way I handled that case in a complex web-app was to have a print stylesheet that hid everything but a special DIV. If the user clicked print, they would get a warning message. If they clicked the print button, then that div would be populated with the correct information. It’s not great, but at least they didn’t get several pages of garbage.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a print button with id=print_req . I wrote some Javascript code for
I have a SQL Report that insists on printing an extra blank page at
I've been asked to provide some tricky printing functionality to a dynamicly generated page.
I have a javascript function which get datagrid's header into THEAD tags. This code
I have commended out the problem lines so show the working code: <%@ Page
I am using a javascript code to print an image with some text as
I have a PHP code: if($billing_total>$limit_to_send){ echo '<script type=text/javascript> window.onload = function() { alert(Sorry,
How can I detect the number of printing page will be on a form
Here is my code: <li class=det_price> <a href=/designer/customize/278258?dpid=1>Printing</a> from $10 </li> I have about
I'm printing a page of my PHP application with the ( ctrl + P

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.