I'm invoking the navigator print function using a simple window.print(); call. It prints perfect (I want to print the same I see on the screen, so I don't really use a special CSS to print) but it showing the link locations next to the text link, something like:
Homepage (http://localhost)
To be clearer: I don't want to have the link locations near the links in the printed version, I have control over the CSS but I can't find this behaviour defined anywhere, so I think is a navigator-related issue!
EDIT:
This happens under Firefox 3.6.8 and the last Chrome, on Ubuntu an Windows XP/Vista.
So to avoid additional print-out of link information in a printed web page, add the following rules to the #media print section:
a:link:after, a:visited:after {
content: "";
}
This will remove the ugly link information like Homepage (http://localhost) and reduce it to Homepage. You may of course add rules to avoid it only in the text section (or only in the navigation, but you shouldn't display navigation in the print-out format of your web page.
Seems you are printing a page with this styling from a CSS2 compliant browser
http://www.alistapart.com/articles/goingtoprint/
In a fully CSS2-conformant browser, we
can parenthetically insert the URLs of
the links after each one, thus making
them fairly useful to anyone who has a
copy of the printout and a web browser
handy. Here’s the rule, which
restricts this effect to the “content”
div and thus avoids sticking a URL in
the masthead:
#content a:link:after, #content a:visited:after {
content: " ("attr(href) ") ";
font-size: 90%;
}
Try it out in a Gecko-based browser,
like Mozilla or Netscape 6.x. After
every link in the printout, you should
see the URL of the link in
parentheses.
content: ""; does not work
I use this:
#media print {
.noprint {display:none !important;}
a:link:after, a:visited:after {
display: none;
content: "";
}
}
This works to disable!
Currently using the content property should work in all major browsers.
#media print - or - <style type="text/css" media="print">
a:link:after, a:visited:after {
content: normal; //TODO: add !important if it is overridden
}
More options here: CSS Content.
More usefull ways of using the content attribute here: CSS Tricks
My app server (rails) required me to use a parent selector. The body element is perfect for selecting what should be the entire page.
body a:link:after, body a:visited:after {
content: "";
}
I found the other solutions don't work (anymore) cross-browser.
The following works in FF 29, Chrome 35, IE 11:
a:link:after, a:visited:after {
content: normal !important;
}
For anyone using Bootstrap 3, the selector used is:
a[href]:after { }
And can be overriden with something like:
a[href]:after {
content: initial;
}
Use additional CSS for print.
See here:
http://www.webcredible.co.uk/user-friendly-resources/css/print-stylesheet.shtml
Adding this will help you to remove those unwanted links
<style type="text/css" media="print">
#page
{
size: auto; /* auto is the initial value */
margin: 0mm; /* this affects the margin in the printer settings */
}
Reading this will help
While many css options have been suggested, if you wish to get rid of the links and headings in the header/footer which is forced on each page, there is a setting just for you. As shown below.
That's it.
I found the mentioned CSS and removed it but it did not help, and I couldn't find it anywhere else in the project so I used jQuery to remove the links but still retain the text.
$('a[title="Show Profile"]').contents().unwrap();
More info here Remove hyperlink but keep text?
I faced the same problem, if you're using chrome, the trick is when displaying the print window, this one contains a left config panel which gives some configuration of display mode and other, there is a link below named : more params or more config (I had in french so I tried to translate it ), click on it after that it will show some additionnal options, among them, there is a check box "header and footer" uncheck it, and it will hide the "localhost...."
hopefully it will help
Every browser having setting of printing header and footer ,and background graphics
If you disable this setting of printing header and footer then it will not show on your print page
Related
I want to remove the URL that gets printed on the bottom of the page.
like:
yomari.com/.../main.php?sen_n
How can it be omitted or prevent from getting printed?
To be more specific, is there any way I can prevent the page URL, date and the page title being printed along, while printing the web page?
Following code sample will work for you,
<style type="text/css" media="print">
#page {
size: auto; /* auto is the initial value */
margin: 0; /* this affects the margin in the printer settings */
}
</style>
see the answer on Disabling browser print options (headers, footers, margins) from page?
and specification of the #page
i found something in the browser side itself.
Try this steps.
here i have been mentioned the Steps to disable the Header and footer in all the three major browsers.
Chrome
Click the Menu icon in the top right corner of the browser.
Click Print.
Uncheck Headers and Footers under the Options section.
Firefox
Click Firefox in the top left corner of the browser.
Place your mouse over Print, the click Page Setup.
Click the Margins & Header/Footer tab.
Change each value under Headers & Footers to --blank--.
Internet Explorer
Click the Gear icon in the top right corner of the browser.
Place your mouse over Print, then click Page Setup.
Change each value under Headers and Footers to -Empty-.
This helped me:
Print page without links
#media print {
a[href]:after {
content: none !important;
}
}
Having the URL show is a browser client preference, not accessible to scripts running within the page (let's face it, a page can't silently print themselves, either).
To avoid "leaking" information via the query string, you could submit via POST
If you set the margin for a page using the code below the header and footers are omitted from the printed page. I have tested this in FireFox and Chrome.
<style media="print">
#page {
size: auto;
margin: 0;
}
</style>
Browser issue but can be solved by these:
<style type="text/css" media="print">
#media print
{
#page {
margin-top: 0;
margin-bottom: 0;
}
body {
padding-top: 72px;
padding-bottom: 72px ;
}
}
</style>
I am telling you about Mozilla Firefox ( I hope it should be same way in other browsers also).
Click on Firefox menu , Go to Print , Select Page Set Up from sub menu of Print. A pop will come up on your screen, there go to "Margin & Header /Footer" tab.
In that select "BLANK" for header / footer as per requirement before printing. You can check the preview for confirmation.
I hope this will help.
Nowadays, you can use history API to modify the URL before print, then change back:
var curURL = window.location.href;
history.replaceState(history.state, '', '/');
window.print();
history.replaceState(history.state, '', curURL);
But you need to make a custom PRINT button for user to click.
You can remove the url dispalying on the printed document via your browser settings.You just click file->page setup->header and footer set all things as blank.if you hav ie,you just remove &U from footer textbox.hopefully this will help you
#media print { a[href]:after { content: none !important; } }
This is working fine for me using jquery
<style>
#media print { #page { margin: 0; }
body { margin: 1.6cm; } }
</style>
I do not know if you are talking about a footer within your actual graphic or the url the print process within the browser is doing.
If its the url the print process is doing its really up to the browser if he has a feature to turn that off.
If its the footer information i would recommend using a print stylesheet and within that stylesheet to do
display: none;
For the particular ID or class of the footer.
To do a print stylesheet, you need to add this to the head.
<link rel="stylesheet" type="text/css" href="/css/print.css" media="print" />
In Google Chrome, this can be done by setting the margins to 0, or if it prints funky, then adjusting it just enough to push the unwanted text to the non-printable areas of the page. I tried it and it works :D
On Chrome 57 the following worked for me, if you have control of the HTML page that needs to be printed (in my case I needed to print a small 3x1 inch label):
remove the HTML title element from header (either temporarily using jquery or permanently if that page does not really need a title)
set the #page margin to 0 as mentioned by #Chamika Sandamal
This resulted in printing a page that only contained the body text, no URLs, no page #s etc.
I would agree with most of the answers saying that its a browser settings but still you can achieve what you want via COM. Keep in mind that most browsers will still have issue with that and even IE will raise the COM security bar to users. So unless its not something you are offering within organisation, don't do it.
I have the same problem. I wonder if it is possible to create the HTML for printing via a jquery plugin: http://www.recoding.it/?p=138
Then send the HTML to a php script (using an ajax call), generate a pdf with http://www.xhtml2pdf.com/ or http://code.google.com/p/wkhtmltopdf/.
Afterwards the pdf could be displayed (by setting the appropriate content type and direct rendering) or displayed by a http-Redirect to the generated pdf.
The generated pdfs in the pfd_for_printing-folder could act as cache and be deleted by a job once a day.
<style type="text/css" media="print">
#page {
size: auto;
margin: 0;
}
</style>
//now set manual padding to body
<style>
body{
padding-left: 1.3cm;
padding-right: 1.3cm;
padding-top: 1.1cm;
}
</style>
Chrome headless now supports an extra options --print-to-pdf-no-header which removes header and footer from the printed PDF file
Perhaps you could try chrome (Probably Safari also)
The url & the page number in the header & footer is not visible when I print to pdf on OSX with Google Chrome.
Sorry not sure if this applies to windows
I have a trick to remove it from the print page in Firefox. Use this:
<html moznomarginboxes mozdisallowselectionprint>
In the html tag you have to use moznomarginboxes mozdisallowselectionprint. I am sure it will help you a lot.
This will be the simplest solution. I tried most of the solutions in the internet but only this helped me.
#print {
#page :footer {
display: none
}
#page :header {
display: none
}
}
#media print {
#Header, #Footer { display: none !important; }
}
Check this link
The browser that I have to support is Chrome (using electron for my project), so using any other browser is not an option.
I've looked for the solution to this problem for a while, it doesn't seem to have an answer to it. I've tried using this form of approach (copied from CSS page x of y for #media print):
The CSS is:
#content {
display: table;
}
#pageFooter {
display: table-footer-group;
}
#pageFooter:after {
counter-increment: page;
content: counter(page);
}
And the HTML code is:
<div id="content">
<div id="pageFooter">Page </div>
multi-page content here...
</div>
The approach above works on FF but not on Chrome. It seems like thead/tfoot of chrome repeats on every printed page on print preview, but it doesn't results in any counter increment. The same counter value is printed on every printed page.
I also tried approaches that involve #page, but this seems to stop working a couple of years ago.
Example (copied from Browser Support for CSS Page Numbers):
#page {
counter-increment: page;
counter-reset: page 1;
#top-right {
content: "Page " counter(page) " of " counter(pages);
}
}
Does anyone know a workaround for this problem? Or Am I dead in the water? Any javasript/nodejs solution is welcome.
If you are looking to add page numbers when printing under Chrome/Chromium, one easy solution is to use Paged.js.
This JS library takes your HTML/CSS and cuts it into pages, ready to print as a book, that you will preview in your browser. It makes the #page and most the CSS3 specifications work for Chrome.
Solution if you are OK with cutting your view into pages, ready to print
Just add their CDN in the head tag of your page :
<link href="path/to/file/interface.css" rel="stylesheet" type="text/css">
You can then add page numbers by using the automated counter page. Example :
HTML to put anywhere you want to display the current page number:
<div class="page-number"></div>
CSS to make the number appear in the div :
.page-number{
content: counter(page)
}
The library also allows to easily manage page margins, footers, headers, etc.
Solution if you want to show numbers (and page breaks) only when printing
In this case, you need to apply the Paged.js CDN only when printing the document.
One way I can think of would be to add a print me button that fires Javascript to :
add the CDN to the page
and then execute window.print(); to launch the printing prompt of the navigator
This is how my Html page looks in print view.
I need to put it on new page when it breaks in 2 and for that need to insert below div before these elements (something which I am doing for other predefined new pages).
<div style='page-break-before: always'>
But I am not able to do so as these contents are dynamic and I have no idea exactly which HTML element will fall at this place.
If I somehow manage to track HTML element at page break point, I will simply put page-break code just above it. This need to be done on html page with jQuery as print view doesn't support js.
I tried to do it like this but failed here as well. Looks like print view doesn't support position: absolute.
$(document).ready(function(){
$("body").append("<div style='position: absolute;top: 760px;page-break-before: always'>");
});
Try this article
Make Sure You use
#media print {
.page-break { display: block; page-break-before: always; }
}
As page-break-* doesn't work on google chrome, here is the solution which worked for me. I set display: inline-block for all the HTML Element which I don't want to get separated between two pages.
.msgbx,.svnotice, .imgdescbx img {
display: inline-block;
}
I want to print the div tag content by javascript by using the following code.
var divToPrint1 = $('#PrintDoc').html();
var newWin = window.open('Share Certificate #001', '', 'width=10px,height=10px');
newWin.document.open();
newWin.document.write('<html><body onload="window.print();">' + divToPrint1 + '</body></html>');
newWin.document.close();
setTimeout(function () { newWin.close(); }, 10);
And print code works fine. But now I want to remove the url, date and title from the printed page by using the javascript code.
Is it possible?
Can you help me to solve the following code?
The only online application I have seen that prints without the header and footer is Google Docs. However, after some searching I discovered that gdocs actually generates a pdf file, opens that file, and the prints from there. If that's the best way that Google has found to do it, with all their resources, I would suggest looking that direction.
"The headers and footers are put there
by your printing subsystem, not by the
page or the browser. What that means
is, this particular attribute is in
the hands of the user. Much like
screen resolution or brower width." -
an answer from a webdesign forum
This is a service (paid though) that I found that will generate a pdf via http post. And here is a (seems promising) s.o. question about generating pdfs using asp.net
<style type="text/css" media="print">
#page
{
size: auto;
margin: 0mm;
}
body
{
background-color:#FFFFFF;
border: solid 1px black ;
margin: 0px;
}
</style>
There exists no way to remove the browser's header and footer from printed pages from JavaScript. Either the user will have to turn those off manually or you will have to render the content as a PDF file on the server, as Adobe Reader does not add a header or footer.
Try the following css code snippet
<style type="text\css" media="print">
#myFooter, #myHeader
{
display: none;
}
</style>
there is solution in the browser side itself.
mentioned the Steps to disable the Header and footer in all the three browsers.
Chrome
Click the Menu icon in the top right corner of the browser.
Click Print.
Uncheck Headers and Footers under the Options section.
Firefox
Click Firefox in the top left corner of the browser.
Place your mouse over Print, the click Page Setup.
Click the Margins & Header/Footer tab.
Change each value under Headers & Footers to --blank--.
Internet Explorer
Click the Gear icon in the top right corner of the browser.
Place your mouse over Print, then click Page Setup.
Change each value under Headers and Footers to -Empty-.
By default, when you print a web page, the page title and and URL are printed at the top of the page, and likewise the date and time are printed at the bottom.
It is possible to remove this additional as you are printing through the PAGE SETUP menu (under FILE in Internet Exp)
Does anyone know of a way of doing this via CSS or javascript?
Historically, it's been impossible to make these things disappear as they are user settings and not considered part of the page you have control over.
However, as of 2017, the #page at-rule has been standardized, which can be used to hide the page title and date in modern browsers:
#page { size: auto; margin: 0mm; }
Print headers/footers and print margins
When printing Web documents, margins are set in the browser's Page Setup (or Print Setup) dialog box. These margin settings, although set within the browser, are controlled at the operating system/printer driver level and are not controllable at the HTML/CSS/DOM level. (For CSS-controlled printed page headers and footers see Printing Headers .)
The settings must be big enough to encompass the printer's physical non-printing areas. Further, they must be big enough to encompass the header and footer that the browser is usually configured to print (typically the page title, page number, URL and date). Note that these headers and footers, although specified by the browser and usually configurable through user preferences, are not part of the Web page itself and therefore are not controllable by CSS. In CSS terms, they fall outside the Page Box CSS2.1 Section 13.2.
... i.e. setting a margin of 0 hides the page title because the title is printed in the margin.
Credit to Vigneswaran S for this tip.
Its simple. Just use css.
<style>
#page { size: auto; margin: 0mm; }
</style>
A possible workaround for the page title:
Provide a print button,
catch the onclick event,
use javascript to change the page title,
then execute the print command via javascript as well.
document.title = "Print page title"; window.print();
This should work in every browser.
You can add this in your stylesheet: #page{size:auto; margin:5mm;}
But this discards the page number too
completing Kai Noack's answer, I would do this:
var originalTitle = document.title;
document.title = "Print page title";
window.print();
document.title = originalTitle;
this way once you print page, This will return to have its original title.
Nothing works for me except the following solution from #Md. Hasibul Huq. You can use it without styles for body:
#media print {
#page {
margin-top: 0;
margin-bottom: 0;
}
body {
padding-top: 5rem;
padding-bottom: 5rem;
}
}
This is not a programming solution (I absolutely know that)
The person who asked this question was seeking an answer with CSS, I am aware of that, and this answer will not help him at all, but it could help others (like me) which brought me to here in the first place.
but It can save your life especially if your client calls you on Weekend to fix it :) (like what happened to me)
quickly she (your client) can expand the "More Settings" and uncheck the "Headers and footers" from Chrome page, as shown in the image below,
Again the programming solution for this problem is as in the accepted answer, I will not repeat it, but if you do not want to deploy your application on Weekend, then this is the way to go
Try this;
#media print{
#page {
margin-top: 30px;
margin-bottom: 30px;
}
}
To add custom page title in the place of about:blank when printing via window.print(): Add the following lines:
document.write('<head>' +
'<title>' +
'My Title' +
'</title>'+ ...)
There's a facility to have a separate style sheet for print, using
<link type="text/css" rel="stylesheet" media="print" href="print.css">
I don't know if it does what you want though.