I'm new learner of JavaScript
...I couldn't find out the difference between window.focus();
and window.blur();
.
<!DOCTYPE html>
<html>
<body>
<button onclick="focus()">Click</button>
<script>
function focus() {
var myWindow = window.open("", "", "width=200,height=100");
myWindow.document.write("<p>A new window!</p>");
myWindow.focus();
}
</script>
</body>
When I am using them I cant find out any action on window by them....
Help me to find out the use of them ...:)
They are basically opposite:
window.focus
Assure that the new window GETS focus (send the new window to the front).
window.blur
Assure that the new window does NOT get focus (send the new window to the background).
Examples:
-window.focus()
:
var myWindow = window.open("", "", "width=200, height=100"); // Opens a new window
myWindow.document.write("<p>A new window!</p>"); // Some text in the new window
myWindow.focus(); // Assures that the new window gets focus
-window.blur()
:
var myWindow = window.open("", "", "width=200, height=100"); // Opens a new window
myWindow.document.write("<p>A new window!</p>"); // Some text in the new window
myWindow.blur(); // Assures that the new window does NOT get focus
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With