我需要从我的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