Back to the 2020 paper

Module III: Basics of Web Programming

20202m

Which of the following is the correct syntax to print a page using JavaScript?

(i) window.print();
(ii) browser.print();
(iii) navigator.print();
(iv) document.print();

Worked SolutionAI Assisted

Correct Answer: (i) window.print();

Explanation:

  • In client-side JavaScript, the window.print() method opens the browser's native Print dialog box, allowing the user to print the current webpage or save it as a PDF.
  • The window object represents the global browser window containing the DOM document.

Example:

<button onclick="window.print()">Print This Page</button>

Note on other objects:

  • browser is not a standard global DOM API.
  • navigator provides browser metadata (user-agent, geolocation, platform).
  • document represents the HTML document tree, but the print() method resides on the top-level window object.

Similar questions