简体   繁体   中英

typescript anchor tag click event in firefox not working

I am creating anchor tag in typescirpt file.on click of this button anchor tag gets created.It works in chrome & IE but not working in firefox.

btnGuest(){
var redirect = <HTMLAnchorElement>document.createElement("a");
      redirect.href = 'https://www.google.co.in/';      
      redirect.target = '_blank';
      redirect.click();
}

<button (click)="btnGuest()"></button>

finally i got the answer after creating element we need to append the element to the document body.here is the code. https://support.mozilla.org/en-US/questions/968992

var redirect = <HTMLAnchorElement>document.createElement("a"); 
document.body.appendChild(redirect); //required in FF, optional for Chrome
redirect.href = 'https://www.google.co.in/';
redirect.target = '_blank'; 
redirect.click();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM