Home Web Front-end JS Tutorial JavaScript closes the current page (window) without any prompts_javascript tips

JavaScript closes the current page (window) without any prompts_javascript tips

May 16, 2016 pm 04:54 PM
window

1. JS code to close the window without any prompt

Copy code The code is as follows:

&lt ;a href="javascript:window.opener=null;window.open('','_self');window.close();">Close</a>

2 .Close the current page (prompt under IE)
Copy code The code is as follows:

< a href="javascript:window.opener=null;window.close();">Close</a>

3. Custom prompt to close
Copy code The code is as follows:

<script language="javascript">
function custom_close() {
if (confirm("Are you sure you want to close this page?")) {
window.opener = null;
window.open('', '_self');
window.close()
} else {}
}
</script>
<input id="btnClose" type="button" value="Close this page" onClick="custom_close()"
/>

4. When the user clicks the "Close" button among the "Maximize", "Minimize", and "Close" buttons of the browser, a closing confirmation dialog will also pop up. Box
Copy code The code is as follows:

<body onbeforeunload="return 'Really want to Close this window?'">
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot Article Tags

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

What is the shortcut key for full screen in Windows 7? What is the shortcut key for full screen in Windows 7? Jun 29, 2023 pm 07:33 PM

What is the shortcut key for full screen in Windows 7?

How to set Google Chrome to open a new window every time How to set Google Chrome to open a new window every time Mar 06, 2024 pm 06:19 PM

How to set Google Chrome to open a new window every time

What should I do if the Win7 taskbar is displayed in the right window of the desktop? What should I do if the Win7 taskbar is displayed in the right window of the desktop? Jun 29, 2023 pm 07:41 PM

What should I do if the Win7 taskbar is displayed in the right window of the desktop?

Windows 10 window color setting tutorial Windows 10 window color setting tutorial Jul 08, 2023 pm 11:25 PM

Windows 10 window color setting tutorial

How to close computer game advertising pop-ups How to close computer game advertising pop-ups Jul 07, 2023 pm 08:57 PM

How to close computer game advertising pop-ups

How to fix a window stuck in airplane mode on Windows 10 How to fix a window stuck in airplane mode on Windows 10 Apr 13, 2023 am 11:07 AM

How to fix a window stuck in airplane mode on Windows 10

How to open two independent windows in Excel? How to open excel windows independently without overlapping How to open two independent windows in Excel? How to open excel windows independently without overlapping Mar 14, 2024 pm 03:10 PM

How to open two independent windows in Excel? How to open excel windows independently without overlapping

How to use keyboard shortcuts to switch between application windows in Ubuntu Unity? How to use keyboard shortcuts to switch between application windows in Ubuntu Unity? Dec 29, 2023 pm 08:27 PM

How to use keyboard shortcuts to switch between application windows in Ubuntu Unity?

See all articles