Mozilla 도움말 검색

고객 지원 사기를 피하세요. 저희는 여러분께 절대로 전화를 걸거나 문자를 보내거나 개인 정보를 공유하도록 요청하지 않습니다. "악용 사례 신고"옵션을 사용하여 의심스러운 활동을 신고해 주세요.

자세히 살펴보기

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();