css - 在 Chrome 中强制打开打印的详细信息/摘要标签

标签 css html google-chrome printing

我尝试在 Chrome 中打印详细信息标签的内容,但我无法强制打开它。

这是我打印 CSS 中的内容:

details, details > * { display:block !important; }

但是只有在打印页面之前打开详细信息才会显示内容。

有没有办法通过 chrome 上的 css print 强制打开细节?

最佳答案

合理的 jQuery 跨浏览器解决方案(非 Opera)...改编自 https://www.tjvantoll.com/2012/06/15/detecting-print-requests-with-javascript/ :

// Set up before/after handlers
var beforePrint = function() {
    $("details").attr('open', '');
};
var afterPrint = function() {
    $("details").removeAttr('open');
};

// Webkit
if (window.matchMedia) {
    var mediaQueryList = window.matchMedia('print');
    mediaQueryList.addListener(function(mql) {
        if (mql.matches) {
            beforePrint();
        } else {
            afterPrint();
        }
    });
}

// IE, Firefox
window.onbeforeprint = beforePrint;
window.onafterprint = afterPrint;

关于css - 在 Chrome 中强制打开打印的详细信息/摘要标签,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19646684/

相关文章:

css - 高度相对于所选元素

html - 如何对齐用户个人资料图片和姓名+其他信息

css - 如何将内部容器移动到外部容器之外?

javascript - 将从组合框获得的javascript变量传递给php而不重定向到另一个页面

javascript - HTML 结构困境 - 使用 POST 或 GET 或 XHR 操作按数据从数据库中删除项目?

visual-studio - 在调试服务时,如何配置 Visual Studio 以使用 --remote-debugging-port=9222 启动 Chrome?

html - 如何使我的 iframe 适合整个部分?

javascript - 使用 jquery 从 textarea 获取 anchor 标签

google-chrome - 对此文件的更改未保存到 google chrome 版本 30.0.1599.101 m 中的文件系统错误

html - Chrome 不会为具有 z-index 和溢出滚动的绝对定位元素的单个子元素显示背景颜色