html-tips-tricks/dialog/index.html
2022-10-03 00:38:45 +05:30

63 lines
No EOL
1.8 KiB
HTML

<!DOCTYPE html>
<html>
<head>
<meta charset='utf-8'>
<meta http-equiv='X-UA-Compatible' content='IE=edge'>
<title>HTML Tips and Tricks - Dialog Tag</title>
<meta name='viewport' content='width=device-width, initial-scale=1'>
<link href="https://fonts.googleapis.com/css2?family=Chilanka&display=swap" rel="stylesheet">
<link rel='stylesheet' type='text/css' media='screen' href='../main.css'>
</head>
<body>
<div class="demo">
<a href="../index.html" class="home">
<img src="../home.svg" alt="home" />
</a>
<h1>Dialog Tag</h1>
<!-- Trigger/Open The Modal -->
<button id="openDlg">Open Dialog</button>
<dialog id="dialog">
<form method="dialog">
<h2>I'm a Dialog</h2>
<p>What do you think of me?</p>
<menu>
<button>Close me</button>
</menu>
</form>
</dialog>
<br><br>
<details>
<summary>see code:</summary>
<p>
The code to implement this Dialog is devided into two parts as below:<br>
The code can be split into 2 parts - i)HTML, ii)JS script. <br>
Code for these two parts are as follows:<br><br>
<b>i) HTML</b><br>
<img src="../code-example-images/dialog-body.png" alt="couldn't load image"/>
<br><br>
<b>ii) Script</b><br>
<img src="../code-example-images/dialog-script.png" alt="couldn't load image"/>
</p>
</details>
</div>
<script>
// Get the modal
const dialog = document.getElementById("dialog");
const btn = document.getElementById("openDlg");
// When the user clicks the button, open the dialog
btn.onclick = function() {
dialog.showModal();
}
</script>
</body>
</html>