URI changes without reload?

不打扰是莪最后的温柔 提交于 2020-01-05 05:52:15

问题


How did they accomplish this function in the theme, where you click on the permalink (eyeball) button the uri changes, with out a hash (#) How is this done? is it ajax? or something else.

I assume it's calling the page but no reload?

theme: http://thingslog-theme.tumblr.com/ (click the eyeball at the bottom of each post)

I'm stumped and help?


回答1:


They use a code of this kind :

$('a').click(function() {
    link = $(this).attr('href')
    history.pushState({}, '', link);
    $('#content').load('/content.php?url='+link)
    return false;
})

with the history pushstate function which allow you to add and modify the browser history entries.




回答2:


We use Backbone + HTML5 pushState to handle the URI changes without the hash. It's works because we follow how Tumblr structures their URLs for all blogs.

We use jQuery.load to handle fetching the html and loading it into the page.

That code looks somewhat like this:

$container.load('http://blog.tumblr.com/post/123 #container', function() {
  var $post = that.$('.overlay-container .post');
  that.view = new App.PostViewFactory.createView($post);

  that.view.on('close', function() {
    window.history.back();
  });
});

Hope that helps.



来源:https://stackoverflow.com/questions/17776567/uri-changes-without-reload

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!