The window object is a window that contains a DOM element. The browser creates a window object for you automatically.
Method | Description |
---|---|
alert() | Displays the alert box. |
prompt() | Shows a dialog window to request user input. |
open() | Opens a new window. |
confirm() | Shows the confirm dialog box, which includes a message, an OK button, and a cancel button. |
setTimeout() | After a certain time has elapsed, the activity is carried out. |
close() | Closes the current window. |
<!DOCTYPE html>
<html lang="en">
<body>
<script>
function hello(){
alert("Hello Aura");
}
</script>
<button type="button" onclick="hello();">Say Hello</button>
</body>
</html>
<!DOCTYPE html>
<html lang="en">
<body>
<script>
function displayWindow(){
var width = window.innerWidth;
var height = window.innerHeight;
alert("Width: " + width + " - " + "Height: " + height);
}
</script>
<button type="button" onclick="displayWindow();">Dimension</button>
</body>
</html>
<script type="text/javascript">
function display(){
var value= prompt("Enter Age");
alert("Your age : "+value);
}
</script>
<input type="button" value="Button" onclick="display()"/>
<script type="text/javascript">
function display(){
open("https://www.techstackguru.com/javascript");
}
</script>
<input type="button" value="Website" onclick="display()"/>
<script type="text/javascript">
function display(){
var value= confirm("Confirm ?");
if(value==true){
alert("Yes");
} else {
alert("No");
}
}
</script>
<input type="button" value="button" onclick="display()"/>
<script type="text/javascript">
function display(){
setTimeout( function() {
alert("Triggered after 5 seconds")
}, 5000);
}
</script>
<input type="button" value="Show" onclick="display()"/>