做Twitter,Hash-Bang#等链接!网址 [英] Doing links like Twitter, Hash-Bang #! URL's

查看:197
本文介绍了做Twitter,Hash-Bang#等链接!网址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


可能存在重复:

什么是Facebook中的shebang / hashbang(#!)和新的Twitter网址?

我想知道Twitter如何运行它的链接。



如果您查看源代码,你使用的链接就像/#!/ i / connect或/#!/ i / discover一样完成,但是它们没有附加到它们的JavaScript函数,比如load('connect')或者其他东西,而且它没有不需要重新加载页面。它只是改变了页面内容。



我看到这个页面,但所有这些文件都必须存在,并且你不能直接去看其中的一个。我想,在Twitter上,这些文件中的每一个都不存在,并且用其他方法处理。如果我错了,请纠正我。



有没有一种方法可以复制这种效果?如果是这样,是否有一个关于如何去做这个的教程?

strong>导航,因为它有时叫,...

  http://whatever.com/path/to/#! / some-ajax-state 

...是临时性问题的临时解决方案,由于现代浏览器标准,这是一个非问题。很可能,Twitter将逐步淘汰,正如Facebook已经在做的那样。



这是几个概念的结合......



过去,链接有两个目的::它加载了一个新文档和/或向下滚动到一个嵌入式锚点, #)。

  http://whatever.com/script.php#fourth-paragraph 

散列之后的URL中的任何内容都不是从服务器请求的,而是由浏览器在页面中搜索的。这一切仍然正常。



通过采用AJAX ,可以将新内容加载到当前(已加载)的页面中。有了这种动态加载,出现了几个问题:1)没有用于书签或链接到这个新内容的唯一URL,2)搜索永远不会看到它。



一些聪明的人通过使用散列作为一种状态引用来解决第一个问题,将其包含在链接&书签。加载文档后,浏览器读取散列并运行AJAX请求,显示页面及其动态AJAX更改。

  http ://whatever.com/script.php#some-ajax-state 

解决了AJAX问题,但搜索引擎问题仍然存在。搜索引擎不会像浏览器一样加载页面并执行JavaScript。

Google可以帮助您解决问题。 Google提出了一种方案,其中任何带有散列(#!)而不是散列(#)的URL都会向搜索机器人建议存在用于索引的备用URL,其中涉及_escaped_fragment_变量的东西。请阅读此处...



https://developers.google.com/webmasters/ajax-crawling/docs/getting-started



今天,随着采用在大多数主流浏览器中使用Javascript的 pushstate ,所有这些都变得过时了。通过pushstate,当内容被动态加载或更改时,当前页面URL可以被修改而不会导致页面加载。当需要时,这为书签和书签提供真实的工作URL。历史。然后可以像往常一样制作链接,不用哈希&哈希爆炸



截至今天,如果您在旧版浏览器中加载Facebook,您将看到哈希爆炸声,但当前浏览器将会演示使用pushstate。


Possible Duplicate:
What’s the shebang/hashbang (#!) in Facebook and new Twitter URLs for?

I was wondering how Twitter works its links.

If you look in the source code, you use the links are done like /#!/i/connect or /#!/i/discover, but they don't have a JavaScript function attached to them like load('connect') or something, and that it doesn't require a page reload. It just changes out the page content.

I saw this page, but then all of those files would have to exist, and you couldn't just go straight to one of them. I imagine that on Twitter each of those files don't exist, and that it is handled in some other method. Please correct me if I'm wrong, though.

Is there a way I could replicate this effect? If so, is there a tutorial on how to go about doing this?

解决方案

"Hash-Bang" navigation, as it's sometimes called,...

http://whatever.com/path/to/#!/some-ajax-state

...is a temporary solution for a temporary problem that is quickly becoming a non-issue thanks to modern browser standards. In all likelihood, Twitter will phase it out, as Facebook is already doing.

It is the combination of several concepts...

In the past, a link served two purposes: It loaded a new document and/or scrolled down to an embedded anchor as indicated with the hash (#).

http://whatever.com/script.php#fourth-paragraph

Anything in a URL after the hash was not requested from the server, but was searched for in the page by the browser. This all still works just fine.

With the adoption of AJAX, new content could be loaded into the current (already loaded) page. With this dynamic loading, several problems arose: 1) there was no unique URL for bookmarking or linking to this new content, 2) search would never see it.

Some smart people solved the first problem by using the hash as a sort of "state" reference to be included in links & bookmarks. After the document loads, the browser reads the hash and runs the AJAX requests, displaying the page plus its dynamic AJAX changes.

http://whatever.com/script.php#some-ajax-state

This solved the AJAX problem, but the search engine problem still existed. Search engines don't load pages and execute Javascript like a browser.

Google to the rescue. Google proposed a scheme where any URL with a hash-bang (#!) in lieu of just a hash (#) would suggest to the search bot that there was an alternate URL for indexing, which involved an "_escaped_fragment_" variable, among other things. Read about it here...

https://developers.google.com/webmasters/ajax-crawling/docs/getting-started

Today, with the adoption of Javascript's pushstate in most major browsers, all of this is becoming obsolete. With pushstate, as content is dynamically loaded or changed, the current page URL can be altered without causing a page load. When desired, this provides a real working URL for bookmarks & history. Links can then be made as they always were, without hashes & hash-bangs.

As of today, if you load Facebook in an older browser, you'll see the hash-bangs, but a current browser will demonstrate the use of pushstate.

这篇关于做Twitter,Hash-Bang#等链接!网址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆