Reputation: 1
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.
Upvotes: 0
Views: 24
Reputation: 21
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;
}
Upvotes: 2