![]() So that, user or programmer can select the appropriate option for printing displayed content on the window screen. Furthermore, when a print() method is called in JavaScript, it opens the print dialog box. Where the contents of the window screen may be text, image, advertisement, etc. For example, you can set if the popup will take place in the current widow (via an. We have learned about the print() method in JavaScript that prints the window screen's content. The jQuery Print Plugin works well and offers a range of settings for you to customize your printing needs. Explanation: window.print(): The window object represents a window containing a DOM document the document property points to the DOM document loaded in that window, window.print() is used to open the Print Dialog to print the current document. Properties: screen.width screen.height screen.availWidth screen.availHeight lorDepth screen. Click the button to print the current page. Window Screen The window.screen object can be written without the window prefix. So, in reference to that iframe, we first obtain the iframe by using it's id, and then it's contentWindow returns a window(DOM) object. Now PrintFun() function is executed that contains window.print() method to print the displayed content on the window screen. JavaScript Window Screen Previous Next The window.screen object contains information about the user's screen. This command basically is the same as window.print(), but as the window we would like to print is in the iframe, we first need to obtain an instance of that window as a javascript object. When we click on the Print button, an onclick function will activate and call the PrintFun() function. The Reset button is used to reset the content, and the Print button is used to print the displayed content. Once we are done with all settings in the Print dialog box, click on the Save button to save the file or page in your system.Įxplanation of the code: In the above program, we have created a student registration form, and this form has two buttons Reset and Print button. Now we fill in all the details of the student registration form and click on the Print button, which shows the below image.Īfter click on the Print button, it shows the different operations of the window.print method. Program to print the Student Registration Form using JavaScript print() method * Display top horizontal bar that contain some information. Browser Support Syntax window. The print () method opens the Print Dialog Box, which lets the user to select preferred printing options. * Create the Outer layout of the Calculator. The print () method prints the contents of the current window. ![]() In this program, we create a student registration form and then print it using window,print() method. Example 2: Program to print the Student Registration Form using the print() method Now we click on the Print button, it opens a print dialog box with the current visual content of the window screen, as shown below. In the above image, there is a Print button. ![]() When we execute the above programming code on any browser, it displays the below image: When we use a print () method, it opens the print dialog box, which allows the user or programmer to select an appropriate option for printing the current content of the window. When silent is set to true, the API will pick the systems default printer if deviceName is empty and the default settings for. ![]() Call the window.print() method when a button is clickedĭocument.getElementById("print_button").Program to print the Current Content of the window using print() method Īs the name suggests, the print () method is used to print the contents of the current window. The `window.print()` method is used to display the print dialog box, which allows the user to print the current document. We’ll look at examples of how to use this method, as well as some tips for getting the most out of it. This blog post will discuss the `window.print()` method in JavaScript and how it can be used to print documents or specific elements on a page.
0 Comments
Leave a Reply. |