All TalkersCode Topics

Follow TalkersCode On Social Media - A Social Media Network for developers Join Now ➔

JavaScript Close Current Window Chrome

Last Updated : Mar 11, 2024

JavaScript Close Current Window Chrome

In this tutorial we will show you the solution of JavaScript close current window chrome, here we needs to use open(), close() available methods in javascript.

The open() method usually opens new tab or window based on chrome settings but here we are going to specifies self location then only we can access that window.

Using close() method we closing that current window too easily.

Step By Step Guide On JavaScript Close Current Window Chrome :-

Here we defined a button ‘CLOSE WINDOW’ with onclick event for loads ‘closew()’ method when user clicks on it.

In script we defined function ‘closew()’, here we collecting current window location using open method with the help of parameters ‘location, _self’ now it contains current window then using close() method we closing our current window or tab when clicks button what we defined in program.

<!DOCTYPE html>
        <title>CLOSE WINDOW</title>
        <button onclick="closew()">CLOSE WINDOW</button>
            function closew(){
  1. <!DOCTYPE html> tag which is instruct the web browser about what version of HTML file written in and it’s not have any ending tag.
  2. The<html> tag is used to indicate the beginning of HTML document.
  3. As above shown <head> tag is contain information about webpage and external file links are declared here. <title> tag is used for set the webpage title.
  4. Both <head> and <title> tags having their pair end tag, so we need to close the ending tags respectively. If you’re not closed anyone of ending tag properly that is also affect the webpage result.
  5. <body> tag is beginning of main coding part because it contain coding of entire website blocks and elements described here.
  6. Here we defined button ‘CLOSE WINDOW’ with onclick event which is used to found when user clicks then it will loads any function which we defined in script so here we specified closew() method in it.
  7. In script function closew() defined in detail there we passing parameters ‘location, _self’ in open() method.
  8. Which is gathering current/active window or tab by open() method and we appending close() method with that for close that window or tab.
  9. As we know close() method which will used for close window or tab by what we specified url.
  10. Both </body>,</html> tags closed respectively. </body> tag indicates the end of body, Then </html> tag indicates the end of HTML document.

Conclusion :-

In conclusion now we are able to know how to close current window or tab using javascript.

When we executes program on browser we can see program button ‘CLOSE WINDOW’ user needs to clicks on that button then with the help of open(), close() methods we are closing current window or tab.

By using this concept we can also close some other specified url of window which we can open in current window or new window that will depends on our passing parameters like _blank,_self..etc.

I hope this tutorial on JavaScript close current window chrome helps you and the steps and method mentioned above are easy to follow and implement.

Author Image About Dikshita

Passionate Electronics and Communication Engineering student with expertise in web development (HTML, CSS, JS,PHP, Bootstrap, React.js) and content writing. Eager problem solver and tech enthusiast, adept at creating engaging web experiences.

Follow Dikshita On Linkedin 🡪