我需要從我的URL中刪除#,以便完成的URL是example.com/sub-page-title而不是example.com/#sub-page-title。從URL中刪除哈希值window.location.hash
我能夠得到一個重複的URL去使用substr(31),31是URL的長度,包括http:// ...但我相信這不是一個理想的方式來做到這一點。
注意:我無法刷新頁面。
點擊後,外部頁面被加載到一個div(然後幻燈片到位)...一旦可見,我希望URL反映(沒有#)。通過這種方式,點擊「返回」將使用戶進入實際頁面。
CODE:
$(document).ready(function(){
var hash = window.location.hash.substr(1);
var href = $('a.load').each(function(){
var href = $(this).attr('href');
});
$('a.load').click(function(){
var toLoad = $(this).attr('href')+' #project-details';
$('.wide-frame').animate({
left: -985,
duration: 'slow'
})
$('#project-details article').hide();
$('#project-details').fadeIn('normal',loadContent);
window.location.hash = $(this).attr('href').substr(31);
function loadContent() {
$('#project-details').load(toLoad,showNewContent)
}
function showNewContent() {
$('#project-details').show('normal');
$.getScript("<?php bloginfo('template_directory'); ?>/scripts/ajax-control.js");
}
return false;
});
});
我不知道這是否是相關的,但我也使用Hash歷史與jQuery燒烤一些其他導航功能。
我相信你想做的事已經在[這個線程(http://stackoverflow.com/questions/3338642/updating-address-bar-with-得到解決什麼新的網址,而無需哈希 - 或重裝浮頁)。 – 2013-03-13 21:25:13