简体   繁体   中英

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".

But with the code below the user is redirected to the same page but the #myRegistrations tab dont stay active. This is beacuse the code below just refreshes the page like "window.location.reload();".

Do you know how to redirect to the same page but with the "#myRegistrations" active? The url that turns the "myRegistrations" tab to active is " 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. Make sure you are using jQuery library because animate function is dependent on it.

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

You can make use of window.location.hash

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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