如何从使用 javascript 的 window.print() 函数打印的页面中删除 url 文本

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/22404309/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-27 23:04:57  来源:igfitidea点击:

How to remove url text from page printed using javascript's window.print() function

javascript

提问by user3138522

Here is my code where I am opening a new window by clicking on a anchor tag. It navigates to try1.php and once clicking on it, it will go to try1.php. (The code is given in the second code.

这是我的代码,我通过单击锚标记打开一个新窗口。它导航到 try1.php,一旦点击它,它就会转到 try1.php。(代码在第二个代码中给出。

try.php

尝试.php

     <script type="text/javascript">
     function newwin() 
     {
       myWindow=window.open('try1.php','myWin','width=400,height=650')
      }
   </script>
   </head>
   <body>
   <a onclick="newwin()">click </a>
   </body>

The code for try1.php is given below

try1.php 的代码如下

   <body>
   <input type="submit" value="print Data"  onClick="window.print()"/>
   </body>

in try1.php, I am having a button on which I have apllied onclcck event. When I click on the button it prints the data but also prints the url text which I don't want.

在 try1.php 中,我有一个按钮,我在上面应用了 onclcck 事件。当我单击按钮时,它会打印数据,但也会打印我不想要的 url 文本。

May I know the way to remove the url text from the printed page?

我可以知道从打印页面中删除 url 文本的方法吗?

回答by Hüseyin BABAL

You can do that with media-dependent style sheetslike below;

您可以使用如下所示的依赖媒体的样式表来做到这一点;

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

And in your your.css;

而在你的your.css;

@media print {
    a {
        display:none;
    }
 }

 @media screen and projection {
    a {
        display:inline;
    }
  }