javascript - trigger click after redirection of a page-JQUERY - Stack Overflow

when i click on a div in a page it redirects to different page and click should be triggered on that pa

when i click on a div in a page it redirects to different page and click should be triggered on that page.I tried the below code but its not working. please help me solve the issue

$('#leaderboardbutton').on('click',function(e){
    window.location='AVM-HomeScreen.html';
    $(window).load(function(){
        $('#leaderboard').trigger('click');
    });
}); 

when i click on a div in a page it redirects to different page and click should be triggered on that page.I tried the below code but its not working. please help me solve the issue

$('#leaderboardbutton').on('click',function(e){
    window.location='AVM-HomeScreen.html';
    $(window).load(function(){
        $('#leaderboard').trigger('click');
    });
}); 
Share Improve this question edited Jan 6, 2014 at 12:00 George 36.8k9 gold badges69 silver badges109 bronze badges asked Jan 6, 2014 at 11:54 user3044827user3044827 11 silver badge3 bronze badges 8
  • How can this possible while user redirects to another page? – Manish Jangir Commented Jan 6, 2014 at 11:56
  • 1 You cannot do that. Don't forget that JS is client side. By the time you've called window.location, the execution of JS on the current page is stopped. There's no way to trigger on a click AVM-HomeScreen.html from within another page... – BenM Commented Jan 6, 2014 at 11:57
  • @ManishJangirBlogaddition. there is a button in AVM-HomeScreen.html which has to be clicked by default when i redirect to this page. – user3044827 Commented Jan 6, 2014 at 11:57
  • You have to trigger the click in the target page, not in the current page where you clicked the link – Kanagu Commented Jan 6, 2014 at 11:58
  • @BenM Thanks.. can i know anyother possible solution ? – user3044827 Commented Jan 6, 2014 at 11:59
 |  Show 3 more ments

1 Answer 1

Reset to default 6

If you have to click a button contained within AVM-HomeScreen.html, you'll need to pass some kind of tracking parameter. For example:

$('#leaderboardbutton').on('click',function(e){
    window.location='AVM-HomeScreen.html?click=true';
});

Next, on AVM-HomeScreen.html, you'll need to check if click == true, and then trigger. For example adding the following JS to AVM-HomeScreen.html should achieve what you need:

if(getParameterByName('click') == 'true')
{
    $('#leaderboard').trigger('click');
}

function getParameterByName(name) 
{
    name = name.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]");
    var regex = new RegExp("[\\?&]" + name + "=([^&#]*)"),
        results = regex.exec(location.search);
    return results == null ? "" : decodeURIComponent(results[1].replace(/\+/g, " "));
}

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745515356a4630963.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信