use javascript to navigate back to the parent window

When I open a new child window from the parent window, there is an HTML form in the child window for user input. Once the form is filled and submitted, the request is sent to the server. I want the response from the server to be redirected back to the parent window, and then automatically close the child window. I hope this explanation is clear enough. Please let me know if you need further clarification. Thank you in advance.

Answer №1

When a pop-up window is generated using the method window.open, it gains access to the originating window through window.opener.

In the parent window, you must establish a function to retrieve information from the pop-up. It would look something like this:

window.getDataFromPopUp = function(info) {
    // process the received data.
};

Subsequently, within the pop-up window, you can invoke this function on the opener in the following manner:

window.opener.getDataFromPopUp(info);

To close the pop-up window, simply utilize the command:

window.close();

Answer №2

Visit jQuery Popup Window Return Value to Parent

The basic idea is as follows:

  1. Create a response that includes a hidden div with the message you want to display (hide it using CSS with display:none;)

  2. The child page should also contain JavaScript code to populate the parent window with the content of the hidden div, like

    parent/* or opener */.document.getElementById(...).innerHTML = ...;

    or invoke a function in the parent window to signal completion, such as
    window.opener/*or parent*/.formIsComplete();
    , where formIsComplete() is a JavaScript function in the parent document/window.

  3. Finally, the last line of JavaScript in the child window should close itself, simply by calling window.close();.

Answer №3

To establish a connection with the parent window from a child window, you can utilize the following method:

window.opener //You can use window.opener to link to the parent window.

After your form submission is successful in the child window, simply execute the following:

window.opener.yourFunc() //YourFunc is a function located on the parent window. Invoke it from the child.

Once the function has been invoked, close the child window by executing:

window.close();

Answer №4

<script type='text/javascript'>
  if (window.opener) {
    window.opener.location.reload();    
    window.close();
  }
</script>

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

Using Express.js to send responses piece by piece

Is it possible to send a response in chunk of data using Express.js? I experimented with this code on an online demo: const express = require('express'); const app = express(); const port = 3111; const sleep = (ms) => { return new Promise(( ...

Blocking of Node.js Promises

I am currently new to Node/JS and am working on developing a password recovery page for an existing IT portal. The page involves searching through AD (ldap) and a DB where users have registered. The goal is to present users with options to authenticate and ...

Timer Tool: JavaScript Countdown Application

I am currently working on a JavaScript countdown timer, but I need help with setting it to only run for 48 hours every time the page is submitted. Right now, when I enter a time, the timer counts down to that specified time. Can someone please assist me ...

What is the best way to assign a data attribute value based on an element's index using jQuery?

I am dealing with multiple sibling elements that are added dynamically or manually using JS. Each element has a data attribute called "data-sec_number" with a number value that increments by one for each subsequent element down the page. Currently, I am ma ...

Gulp Watch fails to identify changes in the SASS SCSS directory

After setting up Gulp to compile SCSS into CSS using NanoCSS and gulp-css for the first time, I encountered an issue. While my do-sass command successfully compiles SCSS and minifies CSS files, it does not run when placed within a watch task. Any changes ...

JavaScript Class Emit Signal for establishing a sequence of interconnected events

My Vue project includes a JavaScript class specifically for mobile devices. I'm looking to have this class emit a signal once the property 'hasEnded' is set to True for my object. How can I achieve this and chain together other events based ...

Angular4 Blueprint

Here is a simple demonstration of ngTemplate that I have coded: <div> <ng-container [ngTemplateOutlet] ="template1"> </ng-container></div> Below are the template examples: <ng-template #template1> This is the 1st template & ...

Arranging divs using inline-block display. How to adjust the heights consecutively?

After much searching and attempting, I am still unable to achieve a simple task. My goal is to apply display inline-block to some divs while aligning them in a row, similar to the image below: https://i.sstatic.net/iLhLS.png The issue arises when number ...

Automatically Dismissing a Bootstrap Alert After a Set Number of Seconds

Having some trouble closing a Bootstrap alert automatically on my new site built using the Bootstrap Framework. The issue arises when trying to close the alert after a certain amount of time. On the main page of the site, there is a modal login form. When ...

Detecting When an Element is About to Be Deleted by Pressing Backspace in a Contenteditable HTML Element

As I develop a text editor using <div contenteditable>, one of my goals is to implement a confirmation message for users before they delete an image element within the editor. My idea is that when a user presses the backspace key while attempting to ...

Transferring information from JSON to HTML

Recently, I came across this handy design tool within our service that helps generate Gauge charts by simply adding a specific div class to the desired pages. <div class="gauge" id="g0" data-settings=' { "value": ...

Is there a repeated call detected in the Readable stream node?

The issue at hand Currently, I have encountered a problem with this code snippet. It involves a Readable stream that retrieves movements from the database in a paginated manner, but it seems to be returning duplicate records inexplicably. const read ...

Having trouble loading this JSON data into my table

So I have a little challenge on my hands: I've got a JSON file with information about various books, each including details like title, author, and year of publication. The goal is to select an option from the list and display the chosen property in ...

Organize every rectangle and text element in D3 into distinct groups

Currently, I am working on creating a bar graph using d3.js. The goal is to display text on top of each bar when the user hovers over it. To achieve this, the <text> and <rect> elements need to be grouped inside a <g> element. For Exampl ...

Form validation in AngularJS for controllers with multiple instances

My specific needs In order to meet the unique requirements of my business, manual validation is necessary. The validation rules can vary in strictness depending on the context in which a specific screen is accessed. It is also important to note that ther ...

The alert function is not being triggered upon receiving a JSON response

I am having trouble with an alert not firing a json response. The response appears in firebug, but after upgrading from php4.4.7 to php5.3.5, I encountered this error. It could be my mistake as well. Could someone please review my code and point out where ...

Discover the art of utilizing two distinct binding strings, wherein upon the selection of either, the alternate binding string shall automatically be

Having to use two different bindingstrings is a requirement due to a tool used for creating PDFs. My objective is to have the corresponding bindingstring turn "Off" when a user clicks on either the Yes or No button, and have the clicked button turn to "Yes ...

When a VueJS button is located within a div that also contains a link, clicking on

Can someone help me with my HTML issue? <a href="/someplace"> <div> <vuecomp></vuecomp> <span>Click row for more info</span> </div> </a> Following is the Vue component I am working on... ...

Tips on transferring a selected value from a dropdown menu to a getJSON URL

I am working on a dropdown menu containing the names of Surahs from the Quran. How can I pass the value of the selected item in the dropdown to a function? $.getJSON("http://api.globalquran.com/surah/2/quran-simple?key=api_key&jsoncallback=?", { ... ...

The image file that was uploaded to our S3 storage has been detected

I'm attempting to upload an image created by cropperjs to a DigitalOcean space. To achieve this, I am utilizing a pre-signed URL and performing a put request using Axios. The problem arises when I try to open the uploaded image, as it appears to be ...