JavaScript window.close() close window syntax

 window.close is a syntax for closing the browser window. A common application is when a user opens a new window on the original web page through window.open to display part of the web page content or logo, and the user needs to give them a close window after reading it. Link or button ( button ), at this time, you can use JavaScript window.close syntax to create the function of closing the window, but window.close has a feature, that is, in many browser environments, the window can only be used after opening the window independently .close Close.


window.close Close the basic syntax of the window

window.close();


If the web window you open is opened through window.open, then use window.close() to make the close window button, and press the close window button to close it directly, if it is not opened through window.open (for example Direct link open), when you close the window, some browsers will pop up a dialog window asking if you want to close it.

Close the window without popping up the dialog window of inquiry, you can write like this

window.opener=null;
window.close();

After adding window.opener=null and then executing window.close(), the dialog window will not pop up.

JavaScript window.close example
Text type: <a href="javascript:window.close();">Close window</a>
Button type: <input onclick="window.close();" value="Close window" type="button" >
Sample output
Text type: Close window
Button type: 
The text hyperlink type and button type close window syntax of the example are quite common design methods. The output result of this example is only indicative, not really effective. It is recommended that you try to use " window.open " first , write A new window can be opened, and use the example syntax in the window to do exercises, you can see the effect of window.close closing the window.

Post a Comment

0 Comments