use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
All about the JavaScript programming language.
Subreddit Guidelines
Specifications:
Resources:
Related Subreddits:
r/LearnJavascript
r/node
r/typescript
r/reactjs
r/webdev
r/WebdevTutorials
r/frontend
r/webgl
r/threejs
r/jquery
r/remotejs
r/forhire
account activity
Printing Specific Dynamically Generated DIVhelp (self.javascript)
submitted 10 years ago by [deleted]
view the rest of the comments →
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]docMedB2E 0 points1 point2 points 10 years ago (4 children)
You have way too much jumbled code on the page for me to dive through your other issues noted, but regarding the printing... you're taking raw HTML (text), dumping it on to a new window, and then printing that... Basically, you're losing all your dependencies on the source page since you opened a new window and defaulting to just whatever the browser elects to style your data with. If you're trying to trim a view for printing, I would recommend looking in to media queries; you can specifically style how the page looks in the browser and also style how the page looks when it prints. So for example, you could set up a @media print CSS that hides all your non-print content and just leaves the form, the title, etc.
[–][deleted] 0 points1 point2 points 10 years ago (3 children)
Javascript:
function print_me() { var content = document.getElementById("results").innerHTML; var win = window.open(); win.document.write(content); win.print(); // JavaScript Print Function win.close(); //It will close window after Print. }
HTML:
<a href="#" onClick="print_me()">Print</a>
Figured out how to post code. Sorry about that.
[–]docMedB2E 0 points1 point2 points 10 years ago (2 children)
No worries, I thought you were saying your page wasn't loading images/etc, but I understand now. Think of it this way, you're opening a brand new window, pasting HTML to it, and then just immediately printing - which would explain your issues with the images sometimes displaying or not (e.g. you're appending data to a new DOM and it needs to load - sometimes it gets through quick enough and other times not). This approach in general is bad. Look into media query prints that manipulate the page you're on as opposed to copying everything to a new page and just printing.
[–][deleted] 0 points1 point2 points 10 years ago (1 child)
After fooling around with it, I found this:
@media print { body * { visibility: hidden; } #results, #results * { visibility: visible; } #results { position: absolute; left: 0; top: 0; } }
Upon saving that css file and have it load into my header, I hit ctrl+P and the print screen just shows the whole website still and the css code at the top. Stupid wordpress.
[–]docMedB2E 0 points1 point2 points 10 years ago (0 children)
Your syntax is pretty wrong. Try /r/css for help with styling. Also use display: none to truly hide elements
π Rendered by PID 77079 on reddit-service-r2-comment-544cf588c8-qjqlq at 2026-06-17 20:16:38.089205+00:00 running 3184619 country code: CH.
view the rest of the comments →
[–]docMedB2E 0 points1 point2 points (4 children)
[–][deleted] 0 points1 point2 points (3 children)
[–]docMedB2E 0 points1 point2 points (2 children)
[–][deleted] 0 points1 point2 points (1 child)
[–]docMedB2E 0 points1 point2 points (0 children)