31
Mi chiedo se sia possibile modificare l'hash in window.location.hash e sostituirlo con "this.id". O dovrei cambiare l'intera window.location?possibile sostituire window.location.hash?
Mi chiedo se sia possibile modificare l'hash in window.location.hash e sostituirlo con "this.id". O dovrei cambiare l'intera window.location?possibile sostituire window.location.hash?
Sì, è possibile. Faccio qualcosa di simile in uno dei miei siti, anche se con href
anziché id
, ma anche lo id
funziona. Un rapido esempio:
$('a[id]').click(function(e)
{
// This will change the URL fragment. The change is reflected
// on your browser's address bar as well
window.location.hash = this.id;
e.preventDefault();
});
Meraviglioso :-) Grazie mille! – circey
È questo cross-browser? – jldupont
@jldupont: dovrei pensarlo. – BoltClock