我正在 typescript 文件中创建 anchor 标记。单击此按钮将创建 anchor 标记。它适用于 chrome 和 IE,但不适用于 Firefox。
btnGuest(){
var redirect = <HTMLAnchorElement>document.createElement("a");
redirect.href = 'https://www.google.co.in/';
redirect.target = '_blank';
redirect.click();
}
<button (click)="btnGuest()"></button>
最佳答案
最后我在创建元素后得到了答案,我们需要将元素附加到文档正文。这是代码。 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();
关于javascript - Firefox 中的 typescript anchor 标记单击事件不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48496967/