admin管理员组文章数量:1429096
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 clickAVM-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
1 Answer
Reset to default 6If 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, " "));
}
本文标签: javascripttrigger click after redirection of a pageJQUERYStack Overflow
版权声明:本文标题:javascript - trigger click after redirection of a page-JQUERY - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745515355a2661505.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论