在链接锚 [英] Anchors in links
本文介绍了在链接锚的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
假设:
- 汤姆 - 启用pushState的,谁拥有现代化的浏览器是
- 弗雷德 - 谁拥有浏览器未pushState的启用它
- 在
super.app </ code> Web应用程序搭载骨干
汤姆浏览到产品/ 1
凡#特殊报价
部分存在的页面。
Tom browses to products/1
page where a #special-offer
section exists.
是否允许骨干汤姆与弗雷德分享的链接,包括锚的特殊优惠部分: http://super.app/products/1#special-offer
Does Backbone allow Tom to share a link with Fred including the anchor to the special-offer section: http://super.app/products/1#special-offer
威尔弗雷德被重定向到 http://super.app/#products/1 (如: :?没有#特殊报价
)
Will Fred be redirected to http://super.app/#products/1 (eg: without the #special-offer
)?
在换句话说,确实骨干允许使用锚
In other words, does Backbone allow to use anchors?
推荐答案
我在这里测试 http://bl.ocks.org/abernier/raw/3183257/
看来是:
- 锚可以启用pushState的的浏览器中使用:
http://bl.ocks.org/abernier/raw/3183257/product1.html#special-offer
- 而IE小于10,它被转换为
http://bl.ocks.org/abernier/raw/3183257/#product1.html
例如:没有#特殊报价
- anchors can be used with pushState-enabled browsers :
http://bl.ocks.org/abernier/raw/3183257/product1.html#special-offer
- while for IE<10, it is converted to
http://bl.ocks.org/abernier/raw/3183257/#product1.html
eg: without#special-offer
我不得不采取关心是禁用基于散列史的浏览器锚,由唯一:
The only thing I had to take care about was to disable anchors for hashes-based history browsers, by:
if (!Backbone.history._hasPushState) {
$('body').delegate('a[href^=#]', 'click', function (e) {
e.preventDefault();
});
}
这篇关于在链接锚的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文