簡體   English   中英

將用戶重定向到同一頁面但重定向到特定選項卡

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

我想將用戶重定向到同一頁面,但是當用戶單擊“ #myRegistrationsClean”時,選項卡“ #myRegistrations”顯示為活動。

但是使用下面的代碼,用戶將被重定向到同一頁面,但#myRegistrations選項卡未保持活動狀態。 這是因為下面的代碼只是刷新了頁面,例如“ window.location.reload();”。

您知道如何重定向到同一頁面但激活“ #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
});

嘗試這樣的事情:

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

下面的代碼將根據您的需要工作。 “ scrollTop”函數用於在窗口中滾動。 確保您使用的是jQuery庫,因為動畫功能依賴於它。

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

您可以使用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