I was looking for a way to simulate a click on <a> tag
as you all know , no success ( the only workaround is by window.open…)
however i found some peaces of code in the net and managed to make it work in :
http://jsbin.com/itujek/5/edit
Chrome
IE
the problem is with FF.
I’ll be glad to share the code with you , and towards a solution which will wrk in FF.
what should i do in this code in order for this code wo work with FF ?
<script>
function doClick(event, myA)
{
if (myA.click)
{
myA.click()
}
else if (document.createEvent)
{
if (event.target !== myA)
{
var tmpEvent = document.createEvent("MouseEvents");
tmpEvent.initMouseEvent("click", true, true, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null);
var allowDefault = myA.dispatchEvent(tmpEvent);
}
}
}
$(document).ready(function(){
$(".myBtn").on('click',function (event)
{ doClick(event, $("#link")[0]); });
});
</script>
</head>
<body>
<a id="link" href="http://www.msdn.com">Normal link</a>
<button type="button" class="myBtn" >
do click</button>
<br />
<br />
</body>
You may try to use jquery.simulate.js :
Supported event types: