How does the Javascript print function work? Can I create a document using javascript and print it off?

后端 未结 8 1579
梦毁少年i
梦毁少年i 2021-02-09 07:17

I know you can use window.print() to print the current page... but what I want to know is can I build a document using javascript in order to populate it with data and print it

8条回答
  •  离开以前
    2021-02-09 07:49

    There are three approaches to printing two of which will work.

    1. Print the entire window: window.print(); will work.

    2. Print only a specific frame: window.parent._frame_id_.print(); will work.

    3. Print a documentFragment will not work (at least in Firefox): document.createDocumentFragment().print();//undefined

提交回复
热议问题