搜索 | 用户支持

防范以用户支持为名的诈骗。我们绝对不会要求您拨打电话或发送短信,及提供任何个人信息。请使用“举报滥用”选项报告涉及违规的行为。

详细了解

Some functionality not working

  • 2 个回答
  • 1 人有此问题
  • 1 次查看
  • 最后回复者为 cor-el

more options

I am developing a website which requires a "a" tag(anchor tag) to be created dynamically and clicked, it is working in other browsers but not in firefox. Below is code snippet: var x = document.createElement("a"); x.href = 'random_url'; x.click(); Please help me out with this.And tell me reason why it is not working

I am developing a website which requires a "a" tag(anchor tag) to be created dynamically and clicked, it is working in other browsers but not in firefox. Below is code snippet: var x = document.createElement("a"); x.href = 'random_url'; x.click(); Please help me out with this.And tell me reason why it is not working

所有回复 (2)

more options

Gecko would not implement the click() method on other elements that might be expected to respond to mouse clicks, such as links (<a> elements), nor would it necessarily fire the click event of other elements.

https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/click

more options

Does it work if you append this element to the body?

  • document.body.appendChild(x);

This works for me in the Web Console:

var x = document.createElement("a");
x.href = 'https://www.google.com';
document.body.appendChild(x);
x.click();