0

Basically, I have been given a task wherein the user has to input data into fields in an HTML file. When all the details are inputted, the user is to click on a button which then opens a new window(not tab) & displays results based on the user input along with additional details.

In the body tag, I've used <button type="button" onClick="Acknowledge()" > </button>

This is supposed to be executed in the function.

function(Acknowledge(){
  //code to display results from inputted fields
}

What do I need to do in order for the results of the function to be displayed in a new window(which obviously does not lead to a new website)? I think that I need to have another .html file in which the results are displayed but don't know how I would put the results in that new file.

1 Answers1

2

u can use a new .html file which get the result from the url. in your current file, you need window.open method to open a new tab. current file:

    window.open('http://youdomain.com/another.html?result=your result');

another.html:

    function getResult(){
        const search = location.search.substr(1);
        let result = '';
        if(search.length > 0){
            search.split('&').forEach((str) => {
                const [key,value] = str.split("=");
                if(key === 'result'){
                    result = value;
                }
            })
        }
        return result;
    }
rayn ma
  • 21
  • 3
  • I would just add this [SO topic](https://stackoverflow.com/questions/901115/how-can-i-get-query-string-values-in-javascript) for more info if necessary – Ludovit Mydla Jul 17 '20 at 11:59