Home Web Front-end JS Tutorial Rewrite the behavior of window.confirm in javascript_javascript tips

Rewrite the behavior of window.confirm in javascript_javascript tips

May 16, 2016 pm 05:49 PM

The window.confirm method in javascript is very useful. It can pop up a confirmation dialog box
Rewrite the behavior of window.confirm in javascript_javascript tips
The reason why we pop up this dialog box may be because the operation is very dangerous, so the user is required to confirm. But if "OK" is selected by default, this principle may be violated.
In addition, the buttons of the confirm dialog box are fixed at "OK" and "Cancel". It may not be very intuitive sometimes.
So, you can consider using msgbox in vbscript to rewrite this behavior. The following is an example

Copy code The code is as follows:

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="WebApplication1._Default" %>




<script> <br>function deleteConfirm(msg) <br>{ <br> function window.confirm(str) <br>{ <br>str= str.replace(/'/g, "'& chr(39) &'").replace(/rn/g, "'& VBCrLf &' "); <br>execScript("n = msgbox('" str "', 289, 'Delete box')", "vbscript"); <br>return(n == 1); <br>} <br>return window.confirm(msg); <br>} <br></script>




onclick="deleteButton_Click" />






For specific details of the msgbox method, you can also refer to the following introduction

The MsgBox function
displays a message in the dialog box, waits for the user to click the button, and returns a value indicating that the user has clicked the button. button to click.
MsgBox(prompt[, buttons][, title][, helpfile, context])
Parameters
prompt
A string expression that is displayed as a message in the dialog box. The maximum length of prompt is approximately 1024 characters, depending on the character width used. If the prompt contains multiple lines, you can use carriage returns (Chr(13)), line feeds (Chr(10)), or a combination of carriage returns and line feeds (Chr(13) & Chr(10)) between the lines. ) separates the lines.
Buttons
Numerical expression, which is the sum of the values ​​​​that specify the number and type of buttons to be displayed, the icon style used, the identity of the default button, and the message box style. See the Settings section for values. If omitted, the default value for buttons is 0.
Title
A string expression displayed in the title bar of the dialog box. If title is omitted, the application's name is displayed in the title bar.
Helpfile
String expression that identifies the help file that provides context-sensitive help for the dialog box. If helpfile is provided, context must be provided. Not available on 16-bit system platforms.
Context
A numeric expression that identifies the context number assigned to a help topic by the author of the help file. If context is provided, helpfile must be provided. Not available on 16-bit system platforms.
Settings The
buttons parameter can have the following values:

Constant Value Description
vbOKOnly 0 Only the OK button will be displayed.
vbOKCancel 1 Displays the OK and Cancel buttons.
vbAbortRetryIgnore 2 Shows the Abandon, Retry and Ignore buttons.
vbYesNoCancel 3 Shows Yes, No and Cancel buttons.
vbYesNo 4 Displays Yes and No buttons.
vbRetryCancel 5 Displays the Retry and Cancel buttons.
vbCritical 16 Display the critical information icon.
vbQuestion 32 Display the Warning Query icon.
vbExclamation 48 Display Warning Message icon.
vbInformation 64 Displays the Information message icon.
vbDefaultButton1 0 The first button is the default button.
vbDefaultButton2 256 The second button is the default button.
vbDefaultButton3 512 The third button is the default button.
vbDefaultButton4 768 The fourth button is the default button.
vbApplicationModal 0 Application Mode: The user must respond to the message box to continue working in the current application.
vbSystemModal 4096 系统模式:在用户响应消息框前,所有应用程序都被挂起。

第一组值 (0 - 5) 用于描述对话框中显示的按钮类型与数目;第二组值 (16, 32, 48, 64) 用于描述图标的样式;第三组值 (0, 256, 512) 用于确定默认按钮;而第四组值 (0, 4096) 则决定消息框的样式。在将这些数字相加以生成 buttons 参数值时,只能从每组值中取用一个数字。

返回值
MsgBox 函数有以下返回值:

常数 按钮
vbOK 1 确定
vbCancel 2 取消
vbAbort 3 放弃
vbRetry 4 重试
vbIgnore 5 忽略
vbYes 6
vbNo 7

설명
helpfile과 context가 모두 제공되는 경우 사용자는 F1 키를 눌러 해당 context에 해당하는 도움말 항목을 볼 수 있습니다.

대화 상자에 취소 버튼이 표시되는 경우 ESC 키를 누르면 취소를 클릭하는 것과 같은 효과가 있습니다. 대화 상자에 도움말 버튼이 포함된 경우 대화 상자에 상황에 맞는 도움말이 제공됩니다. 그러나 다른 버튼을 클릭할 때까지 아무 값도 반환되지 않습니다.

Microsoft Internet Explorer가 MsgBox 기능을 사용할 때 모든 대화 상자의 제목에는 표준 대화 상자와 구별하기 위해 항상 "VBScript"가 포함됩니다.

다음 예는 MsgBox 함수의 사용법을 보여줍니다.
코드 복사 코드는 다음과 같습니다.

Dim MyVar
MyVar = MsgBox ("Hello World!", 65, "MsgBox 예제")
' MyVar에는 클릭한 버튼에 따라 1 또는 2가 포함됩니다.
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 AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Tools

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 should I do if I encounter garbled code printing for front-end thermal paper receipts? What should I do if I encounter garbled code printing for front-end thermal paper receipts? Apr 04, 2025 pm 02:42 PM

Frequently Asked Questions and Solutions for Front-end Thermal Paper Ticket Printing In Front-end Development, Ticket Printing is a common requirement. However, many developers are implementing...

Who gets paid more Python or JavaScript? Who gets paid more Python or JavaScript? Apr 04, 2025 am 12:09 AM

There is no absolute salary for Python and JavaScript developers, depending on skills and industry needs. 1. Python may be paid more in data science and machine learning. 2. JavaScript has great demand in front-end and full-stack development, and its salary is also considerable. 3. Influencing factors include experience, geographical location, company size and specific skills.

How to merge array elements with the same ID into one object using JavaScript? How to merge array elements with the same ID into one object using JavaScript? Apr 04, 2025 pm 05:09 PM

How to merge array elements with the same ID into one object in JavaScript? When processing data, we often encounter the need to have the same ID...

Demystifying JavaScript: What It Does and Why It Matters Demystifying JavaScript: What It Does and Why It Matters Apr 09, 2025 am 12:07 AM

JavaScript is the cornerstone of modern web development, and its main functions include event-driven programming, dynamic content generation and asynchronous programming. 1) Event-driven programming allows web pages to change dynamically according to user operations. 2) Dynamic content generation allows page content to be adjusted according to conditions. 3) Asynchronous programming ensures that the user interface is not blocked. JavaScript is widely used in web interaction, single-page application and server-side development, greatly improving the flexibility of user experience and cross-platform development.

The difference in console.log output result: Why are the two calls different? The difference in console.log output result: Why are the two calls different? Apr 04, 2025 pm 05:12 PM

In-depth discussion of the root causes of the difference in console.log output. This article will analyze the differences in the output results of console.log function in a piece of code and explain the reasons behind it. �...

TypeScript for Beginners, Part 2: Basic Data Types TypeScript for Beginners, Part 2: Basic Data Types Mar 19, 2025 am 09:10 AM

Once you have mastered the entry-level TypeScript tutorial, you should be able to write your own code in an IDE that supports TypeScript and compile it into JavaScript. This tutorial will dive into various data types in TypeScript. JavaScript has seven data types: Null, Undefined, Boolean, Number, String, Symbol (introduced by ES6) and Object. TypeScript defines more types on this basis, and this tutorial will cover all of them in detail. Null data type Like JavaScript, null in TypeScript

How to achieve parallax scrolling and element animation effects, like Shiseido's official website?
or:
How can we achieve the animation effect accompanied by page scrolling like Shiseido's official website? How to achieve parallax scrolling and element animation effects, like Shiseido's official website? or: How can we achieve the animation effect accompanied by page scrolling like Shiseido's official website? Apr 04, 2025 pm 05:36 PM

Discussion on the realization of parallax scrolling and element animation effects in this article will explore how to achieve similar to Shiseido official website (https://www.shiseido.co.jp/sb/wonderland/)...

Can PowerPoint run JavaScript? Can PowerPoint run JavaScript? Apr 01, 2025 pm 05:17 PM

JavaScript can be run in PowerPoint, and can be implemented by calling external JavaScript files or embedding HTML files through VBA. 1. To use VBA to call JavaScript files, you need to enable macros and have VBA programming knowledge. 2. Embed HTML files containing JavaScript, which are simple and easy to use but are subject to security restrictions. Advantages include extended functions and flexibility, while disadvantages involve security, compatibility and complexity. In practice, attention should be paid to security, compatibility, performance and user experience.

See all articles