简体   繁体   English

将用户重定向到同一页面但重定向到特定选项卡

[英]redirect user to same page but to a specific tab

I want to redirect the user to the same page but show the tab "#myRegistrations" as active when the user click in the "#myRegistrationsClean". 我想将用户重定向到同一页面,但是当用户单击“ #myRegistrationsClean”时,选项卡“ #myRegistrations”显示为活动。

But with the code below the user is redirected to the same page but the #myRegistrations tab dont stay active. 但是使用下面的代码,用户将被重定向到同一页面,但#myRegistrations选项卡未保持活动状态。 This is beacuse the code below just refreshes the page like "window.location.reload();". 这是因为下面的代码只是刷新了页面,例如“ window.location.reload();”。

Do you know how to redirect to the same page but with the "#myRegistrations" active? 您知道如何重定向到同一页面但激活“ #myRegistrations”吗? The url that turns the "myRegistrations" tab to active is " http://proj.test/user/profile?user=2#myRegistrations ". 启用“ myRegistrations”标签的网址为“ http://proj.test/user/profile?user = 2#myRegistrations ”。

$('#myRegistrationsClean').click(function() {
    alert("test");
    @if(session('searchedConferences'))
        // $('#cleanSearch').click(); dont works
        window.location.reload();
    @endif
});

Try something like this: 尝试这样的事情:

 .modal-overlay:target { visibility: visible; opacity: 1; } .modal-overlay { position: absolute; top: 50px; bottom: 0; left: 0; right: 0; background: rgba(0, 0, 0, 0.15); transition: opacity 200ms; visibility: hidden; overflow: hidden; opacity: 0; z-index: 10; } 
 <a href="#login-modal">Sign In</a> <div id="login-modal" class="modal-overlay" onclick="(function(e){if(e.path.length<=5)window.location.hash=''})(event)"> Modal Content </div> 

This below code will work as per your need. 下面的代码将根据您的需要工作。 "scrollTop" function used to scroll through the window. “ scrollTop”函数用于在窗口中滚动。 Make sure you are using jQuery library because animate function is dependent on it. 确保您使用的是jQuery库,因为动画功能依赖于它。

jQuery('body, html').animate({scrollTop: jQuery("#myRegistrations").offset().top});

You can make use of window.location.hash 您可以使用window.location.hash

 $('#myRegistrationsClean').click(function() { alert("test"); if(session('searchedConferences')) { // $('#cleanSearch').click(); dont works window.location.hash = "myRegistrationsClean"; window.location.reload(); } }); 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM