我刚才注意到,我们习惯使用的漫长而复杂的Facebook网址现在看起来像这样:
http://www.facebook.com/example.profile#!/pages/Another-Page/123456789012345
据我所知,今年早些时候它只是一个普通的URL片段式字符串(以...开头#),没有感叹号.但现在它是一个shebang或hashbang(#!),我以前只在shell脚本和Perl脚本中看到过.
在新的Twitter的网址,现在还采用了#!符号.例如,Twitter个人资料网址现在看起来像这样:
http://twitter.com/#!/BoltClock
#!现在是否在URL中起了一些特殊的作用,比如某个Ajax框架或某些东西,因为新的Facebook和Twitter界面现在基本上是Ajax化的?在我的URL中使用它会以任何方式使我的Web应用程序受益吗?
我正在寻找一种方法来防止在单击属性#内部的链接后被带到页面顶部href:
<a href="#" onclick="foobar()">click me</a>
Run Code Online (Sandbox Code Playgroud)
然后我遇到了这个简单的解决方案,切换#为#!:
<a href="#!" onclick="foobar()">click me</a>
Run Code Online (Sandbox Code Playgroud)
例如,使用jQuery在线提供了各种其他解决方案:
$('.service').click(function(e) {
e.preventDefault();
});
Run Code Online (Sandbox Code Playgroud)
我最终喜欢#!这么干净但最不喜欢在网上找到任何关于在插入!代码行时实际发生的事情的文档.
题:
究竟是什么#!导致html代码呢?这是防止将用户置于页面顶部的默认操作的好方法,还是这种方法因其他原因而不好?我担心的是它可能是一种与某些浏览器不兼容的hacky方法.
我刚开始使用MEAN堆栈,我正在关注一些TUT.
我正在使用npm-views来自Angular并尝试将html a标记重定向到另一个html文件.但是,当我去的时候,localhost:3000我得到了这个:localhost:3000/#!/当我在该页面内的链接时,它只是添加localhost:3000/#!/#%2Fsl.
我的index.html就是这个(没有一些元素 - 太多的文本//我删除了所有的js和css文件,但我把它们都放在我的文件中):
<!DOCTYPE html>
<html ng-app="firstApp">
<head>
<script type="text/javascript">
var app = angular.module('firstApp',['ngRoute']);
app.config(function($routeProvider){
$routeProvider
.when('/', {
templateUrl: 'home.html',
controller: 'HomeController',
})
.when('/sl', {
templateUrl: 'sl.html',
controller: 'SLController',
});
});
app.controller('HomeController', function ($scope, $http){
console.log('Home page');
});
app.controller('SLController', function ($scope, $http){
console.log('Signup page');
});
</script>
<title>First Node.JS app</title>
</head>
<body>
<div class="container-fluid">
<h1 id="indexTitle"> MyFirst App </h1>
<div ng-view></div>
</div>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
我的home.html文件是这样的:
<div class="container main-forms" id="main-forms"> …Run Code Online (Sandbox Code Playgroud)