I read a lot of questions about resetting zoom level in this community but none of them couldn't resolve my problem. Somebody offered to use from zoom property of CSS, but the problem of this approach is:
When a user changes the browser page's zoom level, this level is considered 100% by the CSS even the real browser level is 500%. Somebody offered to use from scale property of CSS, but the problem of this approach is the same as using the zoom property issue. Also, some different solutions were offered but none of them couldn't resolve my problem.
Then I decided to raise a keyboard event (pressing ctrl + 0
buttons) right after any route changes to reset the browser zoom level to 100% by this code:
shouldComponentUpdate(nextprops) {
window.addEventListener('keypress', (event) => {
console.log("event", event);
});
var keyEvent = new KeyboardEvent('keypress', {
altKey: false,
bubbles: true,
cancelBubble: false,
cancelable: true,
charCode: 0,
code: "Digit0",
composed: true,
ctrlKey: true,
currentTarget: null,
defaultPrevented: true,
detail: 0,
eventPhase: 0,
isComposing: false,
isTrusted: true,
key: "0",
keyCode: 48,
location: 0,
metaKey: false,
repeat: false,
returnValue: false,
shiftKey: false,
type: "keypress",
which: 48
});
window.dispatchEvent(keyEvent);
return nextprops?.location?.pathname != this.props?.location?.pathname;
};
Now when I change the page the console.log("event", event);
run but the browser zoom level doesn't reset.