简体   繁体   中英

Rails: redirect to a specific tab

I have the following tabs:

<div class="container">
<div id="tabs">
  <ul class="nav nav-tabs" id="prodTabs">
    <li class="active"><a href="#search">Search</a></li>
    <li><a href="#other"  data-toggle="tab">Other search</a></li>
  </ul>

  <div class="tab-content">
    <div class="tab-pane active" id="search">

    </div>

    <div class="tab-pane" id="other">
    </div>
</div>

with the following javascript:

<script>
$('#tabs').on('click','.tablink,#prodTabs a',function (e) {
    e.preventDefault();
    var url = $(this).attr("data-url");

    if (typeof url !== "undefined") {
        var pane = $(this), href = this.hash;

        // ajax load from data-url
        $(href).load(url,function(result){
            pane.tab('show');
        });
    } else {
        $(this).tab('show');
    }
});
</script>

<script>
$('a[data-toggle="tab"]').on('shown.bs.tab', function (e) {
    initialize();
});
</script>

The tab named other contains a search form and a map, once the form is submitted I get redirected to a new page. From this new page I would like to be able to go back to the other tab, but I would like to view the same exact content it had when the form was submitted.

Any ideas how I can implement this?

The browser back button does this. You can also add a button to go back:

<button onclick="goBack()">Go Back</button>

<script>
  function goBack() {
    window.history.back();
  }
</script>

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