我目前正在制作一个与我的网站链接的小应用程序。我想知道放置探测器的位置。现在我已将它放在我的应用程序根目录(app.js
)中。
angular.module('myApp', ['ngRoute', 'ngAnimate']).config(function($routeProvider){
'use strict';
$routeProvider
.when('/', {
template: ''
});
}).run(function($rootScope) {
'use strict';
$.expr[':'].external = function(obj){
return !obj.href.match(/^mailto\:/)
&& (obj.hostname != location.hostname)
&& (obj.href.match(/^http\:|https\:/));
};
$('a:external').on('click', function() {
console.log("works");
});
});
这很有效但将它放在app.js
文件中感觉不对。有什么提示吗?
编辑:我对链接的意思是指不在我页面上的链接。 hrefs是另一个域名。