Ecco un altro modo per risolvere il problema.
Prima aggiungere una linea per l'evento click per mostrare l'hash nel AddressBar
$('#myTab').on('click', 'a', function (e) {
e.preventDefault();
// add this line
window.location.hash = $(this).attr('href');
$(this).tab('show');
})
Quindi assicurarsi che la scheda a destra si attiva onload
con l'aggiunta di questa parte per il documento chiamata pronto.
if(window.location.hash){
$('#myTab').find('a[href="'+window.location.hash+'"]').tab('show');
}
Tutti insieme si può scrivere questo:
// cache the id
var navbox = $('#myTab');
// activate tab on click
navbox.on('click', 'a', function (e) {
var $this = $(this);
// prevent the Default behavior
e.preventDefault();
// set the hash to the address bar
window.location.hash = $this.attr('href');
// activate the clicked tab
$this.tab('show');
})
// if we have a hash in the address bar
if(window.location.hash){
// show right tab on load (read hash from address bar)
navbox.find('a[href="'+window.location.hash+'"]').tab('show');
}
utilizza un linguaggio lato server come php? – DG3
utilizzando le guide e la gemma twitter-bootstrap-rails – DanS
non è possibile utilizzare una variabile URL durante l'aggiornamento della pagina e renderla predefinita utilizzando le guide? – DG3