Do modern browsers support onbeforeprint / onafterprint HTML events?

后端 未结 3 540
既然无缘
既然无缘 2021-01-24 01:58

I am trying to update content of my page for printing. I want to have labels (spans) for each input element (textboxes, lists, etc.) to prevent text-cutoff when printing. I want

3条回答
  •  南笙
    南笙 (楼主)
    2021-01-24 02:34

    From MDN onbeforeprint:

    enter image description here


    Well you can always add one event handler to listen for changes and handle updating the content. This is the basic idea [not cross browser friendly]

    document.body.addEventListener("change", function(e){
        var elem = e.target || e.srcElement;
        elem.nextSibling.innerHTML = elem.value;
    });
    

    JSFiddle: http://jsfiddle.net/y4MGE/

    You can use the print style sheet to hide the textboxes when printed and show whatever you want in its place.

提交回复
热议问题