Use of the resizeto() javascript method

Asked

Viewed 23 times

0

I saw an example on MDN and tried to replicate it, but it doesn’t work, I mean, I don’t see the browser window being resized dynamically. Is such a method still used? is it coded correctly? My intention is to start a page HTMLalready with a predefined window size (programmatically).

<!doctype html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>Document</title>
</head>
<body>
<button onclick="quarter()">Pressione aqui</button>

<script>
	function quarter() {
  window.resizeTo(
    window.screen.availWidth / 2,
    window.screen.availHeight / 2
  );
}
</script>
</body>
</html>

1 answer

0


Opa, this method works Fernandes, but only in windows that you yourself initiated:

<!doctype html>
<html lang="en">
	<head>
		<meta charset="UTF-8">
		<title>Document</title>
	</head>
		<body>
			<button onclick="criarMinhaJanela()">Criar janela</button>
			<button onclick="quarter()">Redimensionar</button>

		<script>
			var minhaJanela = null;

			function quarter() {
				if (minhaJanela) {
					minhaJanela.resizeTo(
					minhaJanela.screen.availWidth / 2,
					minhaJanela.screen.availHeight / 2
					);
				} else {
					console.log("Não existe janela...");
				}
			}

			function criarMinhaJanela() {
				try {
					minhaJanela = window.open("", "", "width=100, height=100");
				}
				catch(e) {
					console.log(e);
				}
			}
		</script>

		</body>
	</html>

Obs.: Cannot create window here in stackoverflow, so do not scroll running this code here =)

About creating a page with predefined size, unfortunately I’ve never seen anything like this.

  • Daniel, it was worth a lot for what you already added! This detail of the instantiation!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.