简体   繁体   中英

change print style after button click

This:

<link id="printstyle" href="oldprintstyle.css" rel="stylesheet" type="text/css" media="print" />

$('#printStyle2').click(function () {
    $("#printstyle").attr('href', _printStyle2);
    window.print();
    return false;
});

kind of works. I say kind of, as the actual print style is only applied after I click the button with the id 'printStyle2' a second time. What could be the reason for this behavior? Some kind of caching of the old print style?

The browser needs indeed some time to apply all the changes. So:

window.setTimeout(function() { window.print(); }, 1000);

does the trick.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM