gpt4 book ai didi

javascript - 打印 URL 的内容 - javascript

转载 作者:数据小太阳 更新时间:2023-10-29 06:04:00 24 4
gpt4 key购买 nike

我有一个 php 页面,其中有一个图表、一个日期选择器(日历)和一些按钮。

我想添加另一个按钮“打印图表”,它只打印图表而不是整个页面, 在本地打印机中。

我正在尝试通过另一个脚本(只输出图表)并使用 javascript 函数 'window.print' 来做到这一点

html

<input type="button" onClick="printChart()"   value="Print Chart">

JavaScript

function printChart(){

var myParameters = window.location.search;// Get the parameters from the current page

var URL = "http://my_server/my_folder/my_script_that_outputs_only_my_chart.php"+myParameters;

var W = window.open(URL);

W.window.print(); // Is this the right syntax ? This prints a blank page and not the above URL
}

我试过上面的代码 - 它不起作用。打印空白页。

有没有办法打印目标网址?如果是,是否可以在不打开新窗口的情况下打印它?

谢谢你的时间

最佳答案

您可以使用打印样式表...


<link rel="stylesheet" type="text/css" media="print" href="print.css" />

...除了您的常规样式表。在 print.css 中,只需将所有内容设为“显示:无;”除了您要打印的内容。

关于javascript - 打印 URL 的内容 - javascript,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1094663/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com