This thread was archived. Please ask a new question if you need help.
Some functionality 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
All Replies (2)
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.
Does it work if you append this element to the body?
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();