JavaScript alert () use cases

Organization of dialogue with a visitor to a web resource can be performed in various ways, of which using the JavaScript alert () function is the easiest and fastest option. This option is especially good for testing purposes, but it is used as a natural functionality on many resources.

The JavaScript alert () function provides an affirmative answer. In fact, the important thing is not the answer, but the fact of information output. Moreover, the web resource ceases to function until the user responds. There is always one answer to alert - this is the answer!

javascript alert

In order to debug JavaScript, alert () is an ideal tool that allows you to quickly get relevant information, make a decision and continue to work. But for the normal functioning of the site, he also has a fair amount of advantages.

Visitor Attention Fixation

"Alert" - as in life, forms an event that cannot be passed by. But this event may not happen .

alert javascript

A rare developer knows about this circumstance and painfully debugs his site in its client part. However, few of the developers do not know: it is often so difficult to find an error in the client, that is, in the browser, that:

  • hours of precious time go aimlessly;
  • incredible code transformations are spent;
  • shoveled a lot of scripts, in words, goes to both the browser and the server.

But there is no result. Neither debuggers help, nor words, nor debugging tools built into any browser. Meanwhile, the casket always just opens - the correct key is important.

A simple rule of correct code

First of all, cookies have become the most popular component of a modern site. You should never forget:

  • JavaScript alert & document cookie
  • ===
  • "Here and now" & "in general or someday."

Cookies are a cool opportunity to remember each client in the bowels of the browser, but you should not attach any importance to this in the current session. The main concern of cookies: to remain in the "memory" of the browser in the content that it had at the time the visitor left.

In all other respects, the script code in the bowels of the browser depends only on itself and the events that it processes.

In this context, and this context is ideal here, the code cannot fail to work if it is written correctly. This is the perfect rule for the right code. If the browser displays a clean screen or does something wrong, there is reason to believe that there is an error.

Easier to apply:

  • JavaScript alert ('So far, everything was correct!').

The best debugger or debugger is an event that is supposed to happen, but does not happen .

By moving this construction down from zero to an annoying crime in the code, you can find the place after which it does not work. An error will be found. JavaScript alert () is a modal window . It cannot be bypassed in any way, and there will be nothing further until the developer / visitor closes this window.

If the window does not pop up, then either it is indicated in the code incorrectly, or everything that comes before it contains an error.

A difficult situation in which JavaScript alert does not seem to work

This mainly concerns AJAX algorithms for exchanging information with the server. It is not always acceptable to use classical debugging tools here, and when a multi-level system of objects is acting on the client side, debugging is generally transformed into the consciousness of the developer and no debugger can help.

The best version of the alert in the procedure for communicating with the server is a div (div), which contains the protocol for communicating with the server using the innerHTML method - it will always be clear at what stage the problem occurs.

javascript alert window

The static div that is always visible on the page is not a modal window from the JavaScript alert. Window may not appear, and there may be many reasons for this, and they are syntactically formatted correctly. The browser language is extremely calm in nature and will never take any action if something is not understood and understood.

The static nature of any HTML tag is a good factor. Removing all the code and adding it in portions until the error reappears is not the fastest debugging technology. Writing correctly is a popular, sought-after advice, but not practical.

Browser language - works on events, its main concern is not sequential code, but execution of the functionality assigned to page tags, and event processing.

Additional rule to a simple rule

If the window from the JavaScript alert ('So far, everything is written correctly') did not appear in the browser, it means that the syntax to the place where this construction is written does not raise doubts in the browser and is executed correctly.

The logic of the modern writing style has a significant drawback. All the page files are merged together (with its essence and types) into a single whole, and after that the DOM is built. The order in which files are joined is often significant.

Best of all, when the developer does not attach importance to the event-based principle of organizing the execution of functions assigned to events, but arranges all the functions in the sequence of their application and assignment to tags and page events.

javascript alert document cookie

Order is always the most important thing. JavaScript will figure out the rest: what and when to call. Modern programming in general and in the context of any method, any highly organized object-oriented approach in particular, is always consistent. Codes of scripts are always combined also sequentially as they are described.

If something does not happen, it means: not somewhere, something is wrong, but only in front of this place.

Source: https://habr.com/ru/post/K9912/


All Articles