I have created a form inside a component
HTML
<button type="button" (click)="myForm(i)">
TypeScript
myForm(i) {
let form = document.createElement('form');
form.setAttribute('action', this.urlAddr);
form.setAttribute('id', 'test');
form.setAttribute('target', this.name);
let method = this.name === 'query' ? 'GET' : 'POST';
form.setAttribute('method', method);
let hiddenField = document.createElement('input');
hiddenField.setAttribute('type', 'hidden');
hiddenField.setAttribute('name', 'type');
hiddenField.setAttribute('value', '1');
form.appendChild(hiddenField);
let hiddenFieldTwo = document.createElement('input');
hiddenFieldTwo.setAttribute('type', 'hidden');
hiddenFieldTwo.setAttribute('name', 'sas');
hiddenFieldTwo.setAttribute('value', 'cnt');
form.appendChild(hiddenFieldTwo);
let token = document.createElement('input');
token.setAttribute('id', 'token');
token.setAttribute('type', 'hidden');
token.setAttribute('name', 'secureToken');
token.setAttribute('value', this.securityToken);
form.appendChild(token);
document.cookie = 'Flag=Y';
document.body.appendChild(form);
form.submit();
}
When I attempted to retrieve the value of 'token' field in the new window's TypeScript file, it returned undefined.
TypeScript for the new window
ngOnInit() {
console.log('test'); //this prints but nothing below prints in the new window
let inputElement: HTMLInputElement = document.getElementById('token') as HTMLInputElement;
let inputTwoElement: HTMLInputElement = document.getElementsByName('secureToken')[0] as HTMLInputElement;
if (inputElement) {
const token: string = inputElement.value;
console.log('target token =' + token);
}
if (inputTwoElement) {
const token: string = inputTwoElement.value;
console.log('target tokenTwo =' + token);
}
}
I am puzzled as to why I am unable to retrieve any value. The request is a 'GET' request and the value should be accessible from the parent window. What could be missing or done incorrectly?