Hi,
I'm trying to simulate clicking on a link, but Firefox seems to disable it.
In the sample below, when clicking on the div tag, the onclick event of the link is triggered, but the browser doesn't move to the new location.
could it have to do with security measures?
I'm trying to simulate clicking on a link, but Firefox seems to disable it.
In the sample below, when clicking on the div tag, the onclick event of the link is triggered, but the browser doesn't move to the new location.
could it have to do with security measures?
Code:
<html xmlns="http://www.w3.org/1999/xhtml" > <head> <title>Untitled Page</title> <script type="text/javascript"> function simulateClick(el) { var evt; if (document.createEvent){ evt = document.createEvent("MouseEvents"); evt.initMouseEvent("click", false, false, el.ownerDocument.defaultView, 0, 0, 0, 0, 0, false, false, false, false, 0, null); //evt.initMouseEvent('click', true, true, this.ownerDocument.defaultView, 1, 0, 0, 0, 0, false, false, false, false, 0, null); } //(evt)? el.dispatchEvent(evt):(el.click && el.click()); var check = el.dispatchEvent(evt); } </script> </head> <body> <a id="lnk" onclick="alert('clicked')" href="http://www.google.com/">wow</a> <div style="width:50px;height:50px; background-color:Black" onclick="simulateClick(document.getElementById('lnk'));"></div> </body> </html>
Comment