我有一些简单的 JQuery / Javascript 来为所有外部超链接执行一些简单的逻辑:
<script>
$("a[href^='http://']:not([href*='"+location.hostname+"']),[href^='https://']:not([href*='"+location.hostname+"'])")
.addClass("external")
.attr("target","_blank")
.attr("title","Opens new window").click(function(e) {alert('You are leaving mysite and going somewhere else, you crazy dude')});
</script>
这对于一页来说很好。但是,我希望在我的应用程序的每个网页中都有它,并且 100% 确定它在那里。
有什么好的技巧可以做到这一点吗?
我唯一能想到的是,如果您使用的是 java 架构,那么要有一个基本 JSP 并确保基本 JSP 调用它。
有更好的想法吗?