Figuring out media?

Discussion in 'Javascript' started by Roberto Leibman, Jun 22, 2005.

  1. I haven't been able to figure this out, or find any resource for this.

    I'd like to be able to know, in javascript, if the media that's rendering
    is screen or print. I have no nefarious purpose here (I've often seen
    people wanting to do this to prevent printing): I have a report that uses
    javascript to page 20 items at a time and I want it to show all items at a
    time when printing.

    - I can make it more or less work on IE using onbeforeprint, but no luck
    on better browsers
    - When the page first renders the combination of @print and @screen styles
    work good, but the moment javascript hides stuff it stays hidden (because
    it's changing the element.style attribute of the rows.
    - I've tried figuring it out by having an element with different styles
    declared in the @print and @screen rules of the stylesheet, but I can't
    make it show any difference to the javascript being executed (e.g.
    changing the position of this element for print and screen, the element's
    position is always what is first calculated for the screen).

    Any other ideas?

    Roberto
     
    Roberto Leibman, Jun 22, 2005
    #1
    1. Advertisements

  2. So you want to create a print media only style sheet (and !important )?

    Hence the !important in the print style sheet.

    Yes, it is unlikely that a print renderer would be executing javascript,
    they don't need to be interactive.

    Richard.
     
    Richard Cornford, Jun 22, 2005
    #2
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.