开发者

Dynamically loading stylesheet for print in IE

开发者 https://www.devze.com 2023-01-07 06:01 出处:网络
I have the following code to load a new stylesheet to print a lightbox dialog: $styleUrl = \'../Content/styles/icis.dashboard.colorbox.print.css\';

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 specif开发者_如何学Pythonic code?


This, I believe, will work:

if (document.createStyleSheet) {
    var ieStyleSheet = document.createStyleSheet($styleUrl);
    ieStyleSheet.media = "print";
}


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消