开发者

Can I load new content using AJAX, but change the URL in the omnibar?

开发者 https://www.devze.com 2023-04-05 15:12 出处:网络
I don\'t want to use hashbangs, or shebangs, as they are known. I want to do it the way Facebook does. You click on Profile, the bar remains unchanged and the content is loaded using AJAX. I was wonde

I don't want to use hashbangs, or shebangs, as they are known. I want to do it the way Facebook does. You click on Profile, the bar remains unchanged and the content is loaded using AJAX. I was wondering if the new HTML5 History API could be used.

EDIT: I think I'm going to go ahead and dive into HTML5's history API. Keeping the question open in case anyone h开发者_开发技巧as better suggestions.


The HTML 5 history API is the right way to go.

see here: https://www.new-bamboo.co.uk/blog/2011/02/03/degradable-javascript-applications-using-html5-pushstate/

The pushState and replaceState methods will allow you to change the URL without making an HTTP request. The difference being that pushState pushes a new state on to the history stack, while replaceState replaces the item at the top of the stack.


Also take a look at jquery-pjax


You don't need to do that. You can just prevent the default action from occuring. For instance, with jQuery we have;

function(event) {
  event.preventDefault();
  // this is different from event.stopPropogation()
  // do some stuff
}

this will prevent the link's default action (following the url) from occurring.

P.S. I've always heard shebang refers specifically to this: #!, and not just #, but I could be misinformed...

0

精彩评论

暂无评论...
验证码 换一张
取 消