My objective is not simple redirection!
Even before you mark it as duplicate, I've already tried this, this and this. It didn't worked. I've tried it in following code.
<a href="http://google.com" class="test_class">click me</a>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<script language="javascript">
$("document").ready(function() {
setTimeout(function() {
//$('.test_class').click();
$('.test_class').trigger('click');
},10);
});
</script>
I've tried the click event with and without setTimeout
, nothing worked. I've tried with id as well, it didn't worked. I'm using google chrome Version 44.0.2403.157 (64-bit) on ubuntu 14.04, if at all it matters.
Edit: I've tried following variations as well just now, and they didn't worked :(
$(document).ready(function() { //removed quotes.
setTimeout(function() {
//$('.test_class').click();
$('.test_class').trigger('click');
},10);
});
This one
$(document).ready(function() {
setTimeout(function() {
//$('.test_class').click();
$('.test_class')[0].trigger('click'); //added array representation
},10);
});
And This one, Peculiarity of this click event is that I can see alert, but the click event of <a>
isn't happening.
<a href="http://google.com" class="test_class">click me</a>
<div class="submit_btn" style="display:none;" onclick="dothis();"></div>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<script language="javascript">
function dothis()
{
alert('dskjhfjkds');
$('.test_class').click();
}
$(document).ready(function() {
setTimeout(function() {
//$('.test_class').click();
$('.submit_btn').click();
},10);
});
//$('.test_class')[0].trigger('click');
</script>
p.s. My actual scenario of of click event differs, it is not simple redirection to google website.