更改页面时,使JS更改URL(使用#标签)

时间:2011-11-25 17:31:46

标签: javascript jquery url url-rewriting

我正在使用此JavaScript代码动画并加载我的网站!

$('.down-trigger').on('click', function () {
var toLoad = $(this).attr('href')+' #container';
     $('#container').attr('id','to-go');
     $('#wrapper').append('<div id="newcontainer"/>');
     $('#newcontainer').load(toLoad, function () {
       $('#newcontainer').append($('#container').children()).css({'position': 'absolute', 'top': '696px'});
       $('#to-go, #newcontainer').animate({top:'-=691'},600, function () {
         $('#to-go').remove();
         var lastchild = $('.page:last-child'); // ignore these lines
         var found = lastchild.find('div.slide'); // this one
         if (found.length == 0) { lastchild.remove(); } // and this one
         carousels(); // and this one too
       });
     $('#container').remove();
     $('#newcontainer').attr('id','container');
     searchform(); // these two lines can be ignored too
     triggers(); // this is the second line to ignore
   });
   return false;
});`

当用户点击链接时,你们可以帮助改变网址吗?

我知道我必须使用像window.location.hash这样的东西,但我真的不知道从哪里开始。

感谢。

1 个答案:

答案 0 :(得分:1)

window.location.href = 'myNewUrl.html';