Click here to Skip to main content
15,881,898 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
I am making a program to automatically go to a website and print a page, Can't seem to make it work, I tried selenium chrome driver, problem is it doesn't work. i tried action.sendkeys keys ctrl + shift + "p" to no avail, biggest problem is print preview pop-up. I tried sending JavaScript command: window.print(), but the print preview in chrome stands in my way, because you need to press enter. Is there a way in JavaScript to simulate the pressing of the ENTER key? Please help
Posted
Comments
Sergey Alexandrovich Kryukov 30-Jun-15 20:02pm    
Why? why?!
—SA
naftalie 30-Jun-15 20:06pm    
why what. I have a job which requires me to print out a certain amount of news articles for reading. I am tired of doing it manually
Sergey Alexandrovich Kryukov 30-Jun-15 20:55pm    
This is done by presenting a page on the user's request, so the use could print it when she/he chooses to do so. Please see my answer.
—SA

1 solution

"…because you need to press enter" is something which was set on purpose, otherwise the behavior would be prohibitively intrusive. As JavaScript is most typically stored on the server side, and executed on the client side, it can be anything. That's why JavaScript implementation in browsers is focused on safety — no potentially dangerous access to the local system is allowed.

After all, no one would like printing something without the user concern. If you could do what you want, I would consider it as a crime against me. The computer and printer is mine, no Web application is supposed to decide form me when to press Enter. So, leave it with window.print(); better yest, allow the users to print any page they choose to pay using the browser menu.

For the bonus: there is one aspect of it: you can render the same content for printing differently from screen rendering. You have have different CSS styles depending the media using CSS @media: http://www.w3.org/TR/CSS21/media.html[^].

—SA
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900