Is There A Way To Enable Media Print Css To A Normal View?
I developed a website with a bunch of print media queries to align stuff when printing the page. when you go to the print mode on web browser, the queries works great. but i want a
Solution 1:
In addition to Boldewyn's answer, if you have @media print
styles inside <style>
tags, you can replace them with @media screen
:
Array.prototype.forEach.call(document.getElementsByTagName('style'), function(style) {
style.innerText = style.innerText.replace(/@media print/gi, '@media screen');
});
See the demo.
Solution 2:
To add to yezzz's answer: If you have the print CSS linked in the HTML like
<link rel="stylesheet" media="print" href="...">
you can remove the media
attribute to enable those styles everywhere, either on the server or with Javascript:
document.querySelector('[media="print"]').removeAttribute('media');
Note, that this doesn't work, if the statements in the print stylesheet are wrapped in a @media print {}
rule.
Solution 3:
First thing that comes to mind is use classes. Simple example to give you the general idea. If you had a button that toggles emulateprint
class on the body you could use eg. this css:
body {
color: black;
}
body.emulateprint {
/* put same styles as @media print in here */color: red;
}
@media print {
body {
color:red;
}
}
Post a Comment for "Is There A Way To Enable Media Print Css To A Normal View?"