views:

39

answers:

2

I have the following code to load a new stylesheet to print a lightbox dialog:

    $styleUrl = '../Content/styles/icis.dashboard.colorbox.print.css';
    if (document.createStyleSheet) {
        document.createStyleSheet($styleUrl);
    }
    else {
        $('head').append('<link rel="stylesheet" type="text/css" href="../Content/styles/icis.dashboard.colorbox.print.css" media="print">');
    }

How do i restrict the media type to print in the IE specific code?

+1  A: 

This, I believe, will work:

if (document.createStyleSheet) {
    var ieStyleSheet = document.createStyleSheet($styleUrl);
    ieStyleSheet.media = "print";
}
Scott
+1  A: 

Add onbeforeprint to your body tag:

<body onbeforeprint="loadPrintCSS()">

And the JavaScript/jQuery function:

function loadPrintCSS() {
  $('head').append('<link rel="stylesheet" type="text/css" href="windows-firefox.css" media="print">');
}

This is IE specific, but that was what you asked for.

Gert G
Hi,This isn't working for me.I am trying to print a report which appears in a lightbox dialog.I inject the Print CSS file reference for both IE and Standards compliant browsers when the lightbox has finished loading.Standards compliant browsers print the report fine but IE does not. It prints the background content as well i.e. the content of the whole page including the lightbox.
RyanP13
Sorry about that. The above code works for general use.
Gert G
No problem. Didn't mean to sound ungreatful :)
RyanP13