JavaScript Print to Console | Object | Div | Page | Button

What is the way JavaScript Print the content (data)? This can be confusing because in another language (Java, Python etc) print means, print statement in console only. But in JavaScript Print can use a browser to print a page by the printer. OR Print the data in an HTML div tag. In this tutorial, we will discuss how JavaScript use a “Print Keyword“.

JavaScript Print to Console Object Div Page Button

JavaScript Print Related:-

  • How to print to console – Hello World
  • Print page Using Button
  • A print page on load
  • Javascript print object
  • Print div

JavaScript Print to console chrome & Other browsers

Use a console.log() method to print message in the console. It is use full for developing purposes.

Visible console tab in browser press F12 button. Or you can go through Right click -> inspect element -> console

Output: A screenshot of Safari browser, for another browser it may look different.

JavaScript Print to console chrome & Other browsers

JavaScript Print Page | Button

There is a shortcut keyboard for the javascript print page is ctrl+p. But you can also provide a Button for print page. Where pupup will show with print option.

JavaScript help to use a print function of the window object. You just need to call a window.print() prints the current web page. Let’s see the example code.

Use input tag where value=”print” attribute. Also adding a <script> tag for which will not show confirmation popup after click print button.

Output: See GIF image output of the safari browser.

JavaScript Print Page Button safari

On Chrome browser

JavaScript Print Page chrome

Print page on Load

You can just add line window.print() in <script> tag to javascript print web page on load. See below line of code.

Can Javascript Print Object

Like if you a JSON or other type object and want to print the value for dubbing or another purpose. Then you can do it using -> console.dir(obj). See complete example of it.

Output: Below screenshot of inspect element -> console (Safari Browser)

Javascript Print Object

How JavaScript Print Div Content

Some time HTML div tag need to print the content of it, or any specific tag. You can do it like this example.

Output: Below screenshot of safari browser.

JavaScript Print Div Content

Follow this tutorial link for JavaScript Print Hello World using function Example-

Do comment if you have any doubt, suggestions or questions on this topic.

Note: The JavaScript Print to Console Examples are tested on Safari browser (Version 12.0.2).
OS: macOS 10.14 Mojave
Version: HECMAScript 2018

2 thoughts on “JavaScript Print to Console | Object | Div | Page | Button

  1. Hello Rohit ,

    I have created a calculator with HTML/CSS and now i want to make it functional with JS , but first i need to know how can i print in the console whenever i ciick on button of calc.

    Thank you

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.