search
HomeWeb Front-endJS Tutorial5 jQuery Print Page Options

jQuery Print Plugin allows you to control and customize which parts of the website are printed, providing an alternative to browser default printing capabilities (usually printing the entire window). This article will explore several popular jQuery printing plugins and demonstrate how to build this feature yourself.

5 jQuery Print Page Options

Key points:

  • jQuery Print Plugin allows you to control and customize which parts of the website are printed, providing an alternative to browser default printing capabilities (usually printing the entire window).
  • jQuery Print Preview plugin opens a new browser window to display specific parts of the website for printing. This plugin is very useful for printing data parts such as information cards or a row in a table.
  • jQuery Print Plugin provides a range of settings to customize printing requirements. For example, you can set it to pop up in the current window via iFrame, set the waiting time before the print display renders, and place content before or after the popup.
  • If you want to try a more advanced solution, you can try to create a <iframe></iframe> element dynamically, add it to the page, set the content of <iframe></iframe>, call <iframe></iframe> on .print(), and then for a short time Remove it after delay.

jQuery Print Plugin Overview:

While printing plugins may not be the most exciting plugins, here are some plugins you might want to know about. We will also briefly explain how to build this feature yourself if you want to try a more advanced solution.

Note: Older browsers (I mean IE8) may have abnormal behavior when using certain plugins. However, all modern browsers handle print previews in a consistent way, so keep this in mind if you need full compatibility.

jQuery Print Preview

5 jQuery Print Page Options

This small jQuery plugin allows you to open a new browser window to display specific parts of the website for printing. Unlike some other plugins on this list, this plugin doesn't touch the print functionality of the send browser, it just opens a minimal window (which is perfect, as you can print it directly now).

The purpose of this plugin is when you have some part of the data you want to print, such as an information card or a row in a table. You can open it in a new window (providing configuration options for the plugin) and print from there. This ensures that you only print what you want.

Its browser support seems to be quite comprehensive and works well on my modern browser.

Unfortunately, it is not on GitHub, so it is difficult to know if it is actively maintained. However, this should not stop you, you can see if it works for you and then use it as is.

jQuery Print Plugin

5 jQuery Print Page Options

Don't be fooled by ugly demonstrations. jQuery Print Plugin works well and provides a range of settings for your custom printing needs. For example, you can set whether the popup is in the current window (via iFrame), set the waiting time before the print display renders, and place content before/after the popup.

To start running, just pass it a jQuery object or selector, and the plugin will do the rest.

The author released some submissions in 2016 to improve the plugin. Although there are not many submissions, it seems to be evolving.

jQuery printPage plugin

5 jQuery Print Page Options

Let's talk about this plugin directly. It hasn't been updated in a long time. While some people may be upset by seeing it last updated 6 years ago, others (myself included) can see it as a simple plugin that works fine.

This plugin creates a small mode window with messages and images that is loaded before the main browser print mode loads. It seems to work best when used to point to the anchor marks to what you want to print. You can add printable content to a new page and then use this plugin to print. If your user does not enable JavaScript, it will link normally, opening your content in a new window (where you can print it normally).

jQuery PrintMe

5 jQuery Print Page Options

This plugin is very basic. You just call it on the jQuery element you want to print and it will call the print preview window. There is no real option to speak of, it works exactly as you expect.

Although it doesn't have all the options like other plugins, this plugin is very basic and works well in my test browser. The reason I recommend this is that you can check its source code and see how it goes through step by step in preparing for a print preview. If you want to do it yourself (and add additional features and settings), it is actually a great place to start.

I don't expect this plugin to provide support. Use it, if it works, that would be great! If not, you need to find something else (or you can choose to build it yourself as outlined below).

jQuery Print Preview Plugin

5 jQuery Print Page Options

The last one in the

The list is the jQuery Print Preview plugin. It is designed to provide visitors with a preview of the printed version of the website. Unlike traditional print previews, this plugin contains all content and print styles in a mode window.

In addition, it is published with the SitePoint article, which you can read here: When Visitors Print – About That Print Stylesheet.

The plugin has good browser support (dragged back to IE6), but doesn't seem to offer any other configuration. It also has some unresolved issues, so it can be concluded that it is no longer actively maintained.

How to build this function yourself?

Creating this feature is not too difficult. Most of the work these plugins do behind the scenes is to create a <iframe></iframe> element dynamically, add it to the page (but use CSS to locate it off-screen), set the content of <iframe></iframe>, and call <iframe></iframe> on .print() , and then remove it after a short delay.

The following is how to do this:

function openPrintDialogue(){
  $('<iframe>', {
    name: 'myiframe',
    class: 'printFrame'
  })
  .appendTo('body')
  .contents().find('body')
  .append(`
    <h1 id="Our-Amazing-Offer">Our Amazing Offer</h1>
    <img src="/static/imghwm/default1.png"  data-src="https://img.php.cn/upload/article/000/000/000/173975900525289.png?x-oss-process=image/resize,p_40"  class="lazy" alt="5 jQuery Print Page Options " /></img>  `);

  window.frames['myiframe'].focus();
  window.frames['myiframe'].print();

  setTimeout(() => { $(".printFrame").remove(); }, 1000);
};

$('button').on('click', openPrintDialogue);

Summary:

The industry has turned to no longer printing pages (how often do you print pages?), so it is no surprise that several of these plugins are starting to age.

However, there are some extreme cases where printing the page/page part makes sense. An example is the printing of the event registration/barcode item, as well as a receipt confirmation/purchase proof.

If you are building a website/web application and need to print, you may want to create a print-only CSS file (see: Create a Customized Print Stylesheet in Minutes) and adjust your layout perfectly. Alternatively, you can use the methods outlined above to print only what you are interested in. Both solutions work fine, but the trend seems to be shifting to using CSS to set up print profiles.

(The FAQs part is omitted, because this part of the content has little to do with the plug-in itself and is long, so you can add it yourself as needed)

The above is the detailed content of 5 jQuery Print Page Options. For more information, please follow other related articles on the PHP Chinese website!

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Replace String Characters in JavaScriptReplace String Characters in JavaScriptMar 11, 2025 am 12:07 AM

Detailed explanation of JavaScript string replacement method and FAQ This article will explore two ways to replace string characters in JavaScript: internal JavaScript code and internal HTML for web pages. Replace string inside JavaScript code The most direct way is to use the replace() method: str = str.replace("find","replace"); This method replaces only the first match. To replace all matches, use a regular expression and add the global flag g: str = str.replace(/fi

How do I create and publish my own JavaScript libraries?How do I create and publish my own JavaScript libraries?Mar 18, 2025 pm 03:12 PM

Article discusses creating, publishing, and maintaining JavaScript libraries, focusing on planning, development, testing, documentation, and promotion strategies.

How do I optimize JavaScript code for performance in the browser?How do I optimize JavaScript code for performance in the browser?Mar 18, 2025 pm 03:14 PM

The article discusses strategies for optimizing JavaScript performance in browsers, focusing on reducing execution time and minimizing impact on page load speed.

jQuery Matrix EffectsjQuery Matrix EffectsMar 10, 2025 am 12:52 AM

Bring matrix movie effects to your page! This is a cool jQuery plugin based on the famous movie "The Matrix". The plugin simulates the classic green character effects in the movie, and just select a picture and the plugin will convert it into a matrix-style picture filled with numeric characters. Come and try it, it's very interesting! How it works The plugin loads the image onto the canvas and reads the pixel and color values: data = ctx.getImageData(x, y, settings.grainSize, settings.grainSize).data The plugin cleverly reads the rectangular area of ​​the picture and uses jQuery to calculate the average color of each area. Then, use

How do I debug JavaScript code effectively using browser developer tools?How do I debug JavaScript code effectively using browser developer tools?Mar 18, 2025 pm 03:16 PM

The article discusses effective JavaScript debugging using browser developer tools, focusing on setting breakpoints, using the console, and analyzing performance.

How to Build a Simple jQuery SliderHow to Build a Simple jQuery SliderMar 11, 2025 am 12:19 AM

This article will guide you to create a simple picture carousel using the jQuery library. We will use the bxSlider library, which is built on jQuery and provides many configuration options to set up the carousel. Nowadays, picture carousel has become a must-have feature on the website - one picture is better than a thousand words! After deciding to use the picture carousel, the next question is how to create it. First, you need to collect high-quality, high-resolution pictures. Next, you need to create a picture carousel using HTML and some JavaScript code. There are many libraries on the web that can help you create carousels in different ways. We will use the open source bxSlider library. The bxSlider library supports responsive design, so the carousel built with this library can be adapted to any

Enhancing Structural Markup with JavaScriptEnhancing Structural Markup with JavaScriptMar 10, 2025 am 12:18 AM

Key Points Enhanced structured tagging with JavaScript can significantly improve the accessibility and maintainability of web page content while reducing file size. JavaScript can be effectively used to dynamically add functionality to HTML elements, such as using the cite attribute to automatically insert reference links into block references. Integrating JavaScript with structured tags allows you to create dynamic user interfaces, such as tab panels that do not require page refresh. It is crucial to ensure that JavaScript enhancements do not hinder the basic functionality of web pages; even if JavaScript is disabled, the page should remain functional. Advanced JavaScript technology can be used (

How to Upload and Download CSV Files With AngularHow to Upload and Download CSV Files With AngularMar 10, 2025 am 01:01 AM

Data sets are extremely essential in building API models and various business processes. This is why importing and exporting CSV is an often-needed functionality.In this tutorial, you will learn how to download and import a CSV file within an Angular

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

Safe Exam Browser

Safe Exam Browser

Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools

SecLists

SecLists

SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.