![]() ![]() Then we have defined the button and attached on click listener to it which defines what happens when the button is clicked.Īt last, we have the javascript script which defines the functionality of the above-defined function. Before clicking the close button browser window looks like the below.Īfter clicking the close button, the above page closes.įirst, we created an HTML document and under the body tag, we defined an h1 heading tag that displays Hello World!! and also we have defined a paragraph tag that says to click the button to close the window.The below program demonstrates the approach we discussed above. JavaScript Program to Close a Browser Window Using window.close() Method This method does not any argument and it closes the window on which it is called. Since we opened the new browser window using the javascript script therefore we can close it using the window.close() method. It takes two arguments, the first argument is the current URL which we will access through the location property of the window object and the second argument is the target URL which we will pass as _self because it makes the URL replace the current page.Ĭlosing this opened window using the javascript close method: Opening a new browser window using the javascript open method:įirst, it is needed to open a new browser window using the window.open() method. The below steps demonstrate the approach in which we open a URL using javascript so that it can be closed using the script : Today's security standards do not allow closing the browser windows (using javascript script) that are opened by the user. ![]() ![]() The only thing to be noted here is that we can close only those browser windows that we opened using our javascript script/code. Sometimes it is needed to close a browser window that we opened, we can do this using javascript but due to security reasons, we can close only those browser windows that we opened using javascript script and not the windows that are opened by the user. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |