Reputation: 283
Basically I want to open a new window on click of a button. Once the new window is open I want to change the zoom level to 80%.
After I open the window I take a reference object of the window and try to set the zoom level.
This is a sample code:
function openGoogle(){
var obj = window.open("https://www.w3schools.com");
obj.document.body.style.zoom = 0.8;
}
<!DOCTYPE html>
<html>
<head>
<script data-require="[email protected]" data-semver="3.2.1" src="https://cdn.jsdelivr.net/npm/[email protected]/dist/jquery.min.js"></script>
<link rel="stylesheet" href="style.css" />
<script src="script.js"></script>
</head>
<body>
<h1>Hello Plunker!</h1>
<button onclick="openGoogle()">Open</button>
</body>
</html>
But this doesn't work
Upvotes: 1
Views: 650
Reputation: 10040
This is not allowed by browsers to prevent XSS (cross site scripting).
You can start understanding XSS more here: https://www.owasp.org/index.php/Cross-site_Scripting_(XSS)
What you can do, on the other hand, is pass Window Features
into window.open()
to specify height and width as well as some other flags. (NOTE: I do not have experience with this feature, I'm not fully aware of what it is and isn't capable of)
Window Features Documentation: https://developer.mozilla.org/en-US/docs/Web/API/Window/open#Window_features
Upvotes: 2