GROW

code

Do not use Javascript pop-ups

This issue is found automatically by CODA.
Time to fix: 01h 30min

What are Javascript pop-ups?

JavaScript pop-ups are windows that open on top of a web page and display content from another source. JavaScript pop-ups, while potentially useful in certain circumstances, are generally not recommended due to their potential to disrupt the user experience. They may interrupt the user's workflow, be perceived as annoying if used excessively, and may be blocked by the user's browser. Pop-ups may also be challenging to style in a way that fits seamlessly with the rest of the application.

Why is this an issue?

Using JavaScript pop-ups in ServiceNow can present a number of challenges:

  • Disruptive nature: Pop-ups can interrupt the user's workflow and can be annoying if they are not used sparingly.

  • Blocked by some users: Some users may have pop-ups blocked in their browser settings, which means that the pop-up will not be displayed to them.

  • Difficult to style: It can be difficult to make pop-ups look consistent with the rest of the application, as they are separate windows that are not part of the main application interface.

  • Better alternatives exist: In most cases, there are other ways to achieve the same result that do not involve using pop-ups. These include using modal dialogs, in-page alerts, or inline form validation to provide feedback to users.

How do I fix it?

It is generally recommended to use GlideModal instead of JavaScript pop-ups for creating modal dialogs in ServiceNow. The GlideModal object in ServiceNow is a global object that allows you to create and manipulate modal dialogs in ServiceNow. Modal dialogs are windows that are displayed on top of the main window and require the user to interact with them before they can return to the main window.

There are several advantages to using GlideModal over JavaScript pop-ups in ServiceNow:

  • GlideModal is less disruptive to the user's workflow, as it is displayed within the main window rather than requiring the user to switch to a new window.

  • Pop-ups can be blocked by the user's browser, while modal dialogs are displayed within the main window and are not subject to this limitation.

  • GlideModal provides advanced features such as customizable appearance and the ability to easily add buttons and other interactive elements.

  • Modal dialogs are more efficient than pop-ups, resulting in improved performance and a better user experience.

Here is an example of how to use GlideModal in your code:

1
2
3
4
5
6
7
8
var gm = new GlideModal("UI_dialog_name");

//Sets the dialog title and width of the modal
gm.setTitle("Show title");
gm.setWidth(550);

//Opens the dialog
gm.render();

Overall, using GlideModal can provide a more seamless and intuitive user experience in ServiceNow, as well as providing advanced features and improved performance.