Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/loops/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用javascript在网页上打印所选文本_Javascript_Html_Printing_Textarea - Fatal编程技术网

使用javascript在网页上打印所选文本

使用javascript在网页上打印所选文本,javascript,html,printing,textarea,Javascript,Html,Printing,Textarea,我需要使用javascript只打印HTML页面上文本区域中选定的文本,而不是整个网页。谁能告诉我怎么做 编辑:我使用下面链接上的解决方案以及windows.getSelection来访问所选文本,它成功了 您只能打印一页html 您可能需要使用的是介质查询来隐藏您不想从打印机打印的元素: @media print { .no-print { display:none' } } 或者,您可以使用javascript将所选文本呈现为新页面并打印出来,但这对用户来说

我需要使用javascript只打印HTML页面上文本区域中选定的文本,而不是整个网页。谁能告诉我怎么做

编辑:我使用下面链接上的解决方案以及windows.getSelection来访问所选文本,它成功了


您只能打印一页html

您可能需要使用的是介质查询来隐藏您不想从打印机打印的元素:

@media print {
    .no-print {
        display:none'
    }
}

或者,您可以使用javascript将所选文本呈现为新页面并打印出来,但这对用户来说不一定是一个好的体验。

您可以发布您正在使用的代码以及您已经尝试过的任何内容吗?