Tworzenie i zamykanie okien w javascript

Za pomocą metody window.open() możemy otworzyć nowe okno przeglądarki, a za pomocą window.close() możemy zamknąć aktualne okno.

<!DOCTYPE html>
<html lang="pl">
<meta charset="UTF-8">
<title>Page Title</title>
<meta name="viewport" content="width=device-width,initial-scale=1">
<script> 
    function openNewWindow(){
        window.open(); 
    }
</script> 
<body>
    <button id="panel" onclick="openNewWindow()">Click me</button> 
</body>    
</html>

Tworzenie okna z podanym wymiarem i zmiana wymiaru

<!DOCTYPE html>
<html lang="pl">
<meta charset="UTF-8">
<title>Page Title</title>
<meta name="viewport" content="width=device-width,initial-scale=1">
<style>
    .main{
        text-align: center;
    }
</style>
<script> 
    var okno;
    function createNewWindow(){
        okno = window.open("","","width=100, height=100");
    }
    function resizeWindow(){
        okno.resizeTo(300,300);
        okno.focus();
    }
</script> 
<body>
    <div class="main">
        <button onclick="createNewWindow()">Utwórz okno</button> 
        <button onclick="resizeWindow()">Powiększ okno</button> 
    </div>
</body>    
</html>
Ask ChatGPT
Set ChatGPT API key
Find your Secret API key in your ChatGPT User settings and paste it here to connect ChatGPT with your Tutor LMS website.
Scroll to Top