使用 JavaScript 模拟点击链接
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 
原文地址: http://stackoverflow.com/questions/4426617/
Warning: these are provided under cc-by-sa 4.0 license.  You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Simulate a click on a link with JavaScript
提问by cycero
I need to simulate a click on a link using JavaScript. Could anybody tell me how it can be achieved? It should work in FireFox and IE.
我需要使用 JavaScript 模拟点击链接。谁能告诉我它是如何实现的?它应该适用于 FireFox 和 IE。
Thanks in advance.
提前致谢。
回答by Anurag
回答by dheerosaur
As mentioned by others, you can use clickmethod for IE. For Firefox, have a look at element.dispatchEvent. See the example in the documentation.
正如其他人所提到的,您可以使用clickIE 的方法。对于 Firefox,请查看element.dispatchEvent。请参阅文档中的示例。
回答by Jinesh Parekh
this should do the trick
这应该可以解决问题
document.getElementById('yourLink').click();
回答by Bhanu Prakash Pandey
document.getElementById('mylink').click() 

