How can the printing of content be adjusted when the browser zoom function is activated?

Is there a way to prevent the content from zooming when printing while the browser is zoomed in? The goal is for the printing (using iframe) to remain unchanged even if the browser is zoomed. I attempted:

document.body.style.transformOrigin = 'top left';
document.body.style.transform = 'scale(' + scale + ')';

However, this approach does not work correctly when the page is very long.

Answer №1

One way to prevent zooming entirely is by using the following code snippet:

<meta content='width=device-width; initial-scale=1.0; maximum-scale=1.0; user-scalable=0;' name='viewport'>

Answer №2

The following code snippet is what I use:

const adjustPrintPageSize = () => {
        let scale = 1 / window.devicePixelRatio;
        document.getElementById('print-page').style.transform = 'scale(' + scale + ')';
        document.getElementById('print-page').style.transformOrigin = 'top left';
      };
window.addEventListener('resize', adjustPrintPageSize)

This solution has been effective for me.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Individualize JavaScript clients for each module in ExpressJS

Exploring the modular folder structure demonstrated by tjholowaychuk in this video. Is there a way to include a distinct client-side JavaScript file within each module? Currently, all my client JS resides in the /assets/js folder, but having a separate JS ...

Switch between divs based on the current selection

var header = $("#accordion"); $.each(data, function () { header.append("<a id='Headanchor' href='javascript:toggleDiv($(this));'>" + this.LongName + "</a>" + "<br />", "&l ...

What is the best way to run JavaScript code using Python Selenium, and then retrieve the results within my Python script?

After searching for solutions, I came across a Python code snippet that opens my JavaScript file and runs it on the webpage. I stumbled upon discussions about using execute_async_script() to manage callbacks in JavaScript, but the concept still eludes me. ...

Utilizing query parameters in JavaScript

When querying data from the database using passed parameters, I encountered an issue. For example: http://localhost:3030/people?$skip=0&$limit=25&$sort[name]=0&description[$name]=rajiv I wanted to add an extra parameter without including it in ...

Error: Unable to locate the store in either the context or props due to an invariant violation

In the development process, I encountered an issue with my code regarding storing and retrieving user information. My scenario involves creating a store in Login.js where the username is sent to the store upon user login. Subsequently, in Profile.js, I aim ...

Creating a Timeless Banner with the Magic of `background:url()`

I have a banner placed within a div tag that displays my banner image. I am trying to create a fading effect when transitioning to the next image, but I am struggling to achieve this. I attempted to use jQuery fadeIn(), however, it did not work as expected ...

The error message "TypeError: usert.addItem is not a function" indicates that

Currently in the process of developing a discord bot using discord.js, sequelize, and sqlite for database management. Encountering an issue with a custom function that is not being recognized as defined by the terminal, despite me confirming its definition ...

What is the best way to alter the order of the .map function in JavaScript to display in ascending or descending order?

I currently have 25 songs in my Spotify playlist, with the possibility of more being added in the future. The songs are numbered from 1 to 25. However, the map() function I use only displays the top 10 songs (1 to 10). When a new song is added, it is assig ...

Leverage both props and destructuring in your Typescript + React projects for maximum efficiency!

Is it possible to use both destructuring and props in React? For instance, can I have specific inputs like name and age that are directly accessed through destructuring, while also accessing additional inputs via props? Example The desired outcome would ...

The menu is about to receive some custom styling

I have come across a webpage where I need to make some modifications, but I am unable to locate the script responsible for applying the inline style. This issue only seems to be occurring on the mobile version with the dropdown menu. <div class="is-dri ...

What is the best way to merge two JSON arrays using Axios in a React project?

I am currently working on getting data using axios React from Laravel, but I am facing some challenges in combining two arrays by their respective Ids. In my case, I am trying to retrieve product data and images from the Laravel Controller. Can anyone prov ...

How can I combine multiple requests in RxJS, executing one request at a time in parallel, and receiving a single combined result?

For instance, assume I have 2 API services that return data in the form of Observables. function add(row) { let r = Math.ceil(Math.random() * 2000); let k = row + 1; return timer(r).pipe(mapTo(k)); } function multiple(row) { let r = Math.c ...

The mobile devices are not showing my HTML website

I have implemented the following CSS link code on my website: <link rel="stylesheet" href="index_files/front.css" media="all" type="text/css" > Additionally, I have included the following code <meta name="HandheldFriendly" content="True"> & ...

Having trouble applying overlays to list items with CSS

I'm currently working on a grid gallery where I've set the List items to be 20% wide so there can be 5 in one row using float:left. Now, I'm trying to add an overlay effect by using a div with the class "overlay" so that when someone hovers ...

Express-Session Object Method

I am currently facing an issue with linking an object to an Express session. Below is the code I am using: var express = require('express'); var session = require('express-session'); // Defining an object named "engine" which simulate ...

issue with AngularJS model not initially binding to select dropdown

I am facing an issue with a select dropdown in my code. I am using ng-repeat to populate the dropdown like this: <select ng-model="tstCtrl.model.value" required> <option ng-repeat="option in tstCtrl.myOptions" value="{{option.a}}">{{option.b ...

Extracting JSON data from Stripe results - A comprehensive guide

I'm having trouble displaying the 'amount_total' in an h1 tag from my Stripe JSON response. Every time I try, I encounter this error: TypeError: Cannot read property 'map' of undefined Here is a snippet of the Stripe JSON output: ...

Transferring Data to EJS Template

I have been facing a challenge in passing a value from a POST route to an EJS file for display. Despite trying various methods like redirecting, sending, and rendering the results, the data won't make its way to the EJS file. Below is the POST route ...

Adding a cookie or local storage with React Hooks - step by step guide

I've been diving into a new project with React Hooks and feeling a bit disoriented. I've explored various libraries created by other developers for incorporating cookies using hooks, but I'm hesitant to rely on external dependencies. Can any ...

Deploy your Nodejs project to the build folder or FTP for easy access

Is there a way to successfully publish my NodeJS build folder to an FTP server? I've tried running npm run build in Cmd, but it keeps giving me an error. I have already set NODE_ENV to production in webpack or package.json. 18 error <a href="/cdn ...