admin管理员组文章数量:1391937
I would like to have alternate behavior during a print stylesheet on a web page. Something along the lines of:
If this page is being printed, don't bother calling SWFObject to summon an .swf into existence. Just leave the HTML that the Flash will replace.
I've tried things like setting a known element to a known style that exists for the screen but not for the print stylesheet. But getting a "style" via Javascript doesn't get a puted style.
Summary: In a cross-browser way, is it possible to tell which stylesheet is in effect?
I would like to have alternate behavior during a print stylesheet on a web page. Something along the lines of:
If this page is being printed, don't bother calling SWFObject to summon an .swf into existence. Just leave the HTML that the Flash will replace.
I've tried things like setting a known element to a known style that exists for the screen but not for the print stylesheet. But getting a "style" via Javascript doesn't get a puted style.
Summary: In a cross-browser way, is it possible to tell which stylesheet is in effect?
Share asked Dec 5, 2008 at 20:11 jschrabjschrab 11k4 gold badges22 silver badges17 bronze badges2 Answers
Reset to default 6It sounds like you're confused that print style-sheets are used when you view a printer-friendly page, but that is not the case. A print style sheet isn't applied until the user actually sends the page to the printer. At this point, any javascript that is going to run has already finished.
What you want to do is put your SWFObject inside a div container, and have the container styled as display:none;
for the print media.
You could use JavaScript to access the stylesheets in the document and then check if the 'Print' stylesheet is active. Once you determined which CSS is active then you could manage your content.
The getActiveStyleSheet
function would looks something like this:
function getActiveStyleSheet()
{
var i, a;
for (i = 0; (a = document.getElementsByTagName("link")[i]); i++)
{
if (a.getAttribute("rel").indexOf("style") != -1
&& a.getAttribute("title")
&& !a.disabled)
return a.getAttribute("title");
}
return null;
}
You can find the code here: http://www.alistapart./articles/alternate/.
本文标签: printingHow can one detect via Javascript if a print stylesheet is in effectStack Overflow
版权声明:本文标题:printing - How can one detect via Javascript if a print stylesheet is in effect? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744652240a2617754.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论