JavaScript code to automatically navigate to the HomeScreen when an alert window is closed

After triggering a JavaScript alert, is there a way to automatically navigate to the home screen once the alert is closed?

I want users to be redirected to the Home Screen when they press the close button on the alert.

Is there a way to achieve this behavior?

I attempted to add the following code snippet after the alert:

window.location.href = 'index.html'

However, I found that I was instantly redirected before even seeing the alert. What I actually want is to be redirected only after closing the alert.

Below is my attempt:

function sendEmail() {
    Email.send({
      SecureToken: "a",
      To: "b",
      From: "<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="d7b497b0bab6bebbf9b4b8ba">[email protected]</a>",
      Subject: "Bestellung",
      Body:
        "Body"
    }).then((message) => alert("Bestellung wird bearbeitet"), 
    window.location.href = 'index.html');
  }

Answer №1

According to the information provided here, the second parameter passed to the then() function is meant for handling the rejected case. In your code, you were passing a second argument using a , instead of encapsulating multiple statements within a closure function.

To ensure that the second instruction is executed after the user has closed the alert dialog, it should be structured like this:

.then((message) => {
  alert("Bestellung wird bearbeitet");
  window.location.href = 'index.html';
}

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

What steps should I take to create an object that can be converted into a JSON schema like the one shown here?

I'm facing a rather simple issue, but I believe there's something crucial that I'm overlooking. My objective is to iterate through and add elements to an object in order to generate a JSON structure similar to the following: { "user1": ...

Leverage JSON files for pagination in NextJS

I am currently developing a science website where the post URLs are stored in a static JSON file. ScienceTopics.json- [ { "Subject": "Mathematics", "chapters": "mathematics", "contentList": [ ...

Is it possible to convert (HTML and CSS3 generated content for paged media) into a PDF format?

Would it be possible to convert a HTML document styled with CSS3 Generated Content for Paged Media into a PDF format? If such an application does not exist, what alternatives can I consider as the foundation for developing a converter? Thank you ...

Customize the rendering of DataTables with a flexible number of table headers

Having the same number of table header columns and table data columns is a requirement when using DataTables. However, I am currently dealing with an issue where the number of my <th> tags fluctuates by plus or minus 2 based on certain conditions, wh ...

What is the process for configuring environmental variables within my client-side code?

Is there a reliable method to set a different key based on whether we are in development or production environments when working with client-side programs that lack an inherent runtime environment? Appreciate any suggestions! ...

Transform the JSON.pretty_generate() function into a visually appealing accordion layout

Within my Ruby on Rails application, the JSON file is being dynamically generated via the controller. Currently, I am rendering it using render :json => JSON.pretty_generate(@xml_hash), :status => :ok, and it is displaying in a tree-like structure. ...

Determine if each element in an array is present in the MongoDB document's array

Is it possible to determine whether a specific element exists within an array in a MongoDB document? For instance: If we have the following document { "_id": "A", "userId": "B", "selectedUsers": ["C", "D"] } and another array ["E", "C"]. ...

Is it possible to verify the data within a VueJS model? It seems that none of the Vue validators are effective

Hello there, It's common knowledge that using Vue-validator with most UI components can be challenging when it comes to validation. I've been utilizing Vue Material Components by @mjanys, which is a fantastic library. The author has included met ...

Unspecified data stored within an object

I am looking to populate a page with data from the server and have the ability to update the information. To achieve this, I am using formbuilder to fetch data from the server as the default value. Here's how I am implementing it: createForm(){ ...

Tips for incorporating a custom CSS design into a jQueryUI tooltip

I am struggling to apply my custom CSS class on top of the jQueryUI tooltip. Although the tooltip is displaying correctly, my styles are not being applied. Here is the code I'm using: $(document).ready(function () { $("#roles").tooltip({ content: ...

Utilizing Vector3 for Parametric Geometry calculations

As I update a script to a newer version of three.js, I encountered an issue with ParametricGeometry. The error message "THREE.ParametricGeometry: Function must now modify a Vector3 as third parameter" keeps appearing. Below is the section of code causing t ...

Showcasing a glTF/glb model using three.js in hugo

For my personal website, I am using Hugo with the coder theme. My goal is to showcase a glTF/glb model as the avatar on the home page. I have successfully created an index.html file where I can display a glTF/glb model standalone (without Hugo). <!DOCTY ...

Dynamic placement of divs when new content is added to the page

Before we begin, I'll provide you with the complete HTML code of my webpage: <div align="center"> <img src="http://questers.x10.bz/Header.png" style="position: absolute; margin-left: -440px; box-shadow: 0px 3px 12px 2px #000;" class="rotate" ...

What steps should I take to resolve the push error occurring with the data I set following the JS API request?

I am working on a Next.js application where I need to fetch data from the Open Weather API. However, when I try to define it using [data = list], I encounter an error that says {TypeError: Can't read properties of undefined (reading 'push')} ...

The perplexing nature of the "this" keyword in JavaScript

Original Code - Version 1: const myobj = { a1 : 10, b1 : 20, c1 : 30, myfunc1 :function() { console.log(this) const myfunc2 = function () { let a2 =100 console.log(this) } myfunc2() } ...

Tips for adjusting the placement of the horizontal line in real-time?

I'm working on a new asp.net website. On the page, there is a link button called "Landline number" followed by three textboxes. Below the textboxes, there is a horizontal line. Initially, only the link button and horizontal line are visible, while th ...

Navigation bar in reactjs remains visible even after clicking on an icon button, causing a temporary issue with

I'm facing an issue with my navigation bar created using material-ui. I have an onClick function set up so that when the user clicks the icon button, the navigation redirects to a new page and then should close. However, no matter what I try, the navi ...

Exploring the combined application of the AND and OR operators in JavaScript programming

{Object.keys(groupByMonthApplicants).map((obj,i) => <div key={obj} style={(i > 0 && (this.state.selectedTabId !== 'rejected' || this.state.selectedTabId !== 'approved')) ? {paddingTop:'15px',background:&a ...

Just starting out with AngularJS, running into a problem with ngResource

As a newcomer to AngularJS, I am attempting to create my first app using the reed.co.uk API. Please bear with me as I navigate through this process! :) Currently, my application is very basic and includes the following: index.html <!DOCTYPE html> ...

Setting a restriction for a variable to show a maximum of 50 characters

Is there a way to restrict the anchor text displayed below to just 50 characters? echo '<td style="" class="pointlink"><span class="pointlink"><a href="http://'.$rowad["1site"].'">'.$rowad["1site"].'</a>< ...