带有mootools的XHTML有效外部链接

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了带有mootools的XHTML有效外部链接相关的知识,希望对你有一定的参考价值。

W3C no longer include the target attribute of the <a> tag in html 4.0 Strict and XHTML 1.0 Strict document types . To make links open new windows we will have to use javascript, and with mootools it make this task very easy. Just add this snippet to the bottom of your html document and it will look for all external links on your page and add the target attribute to each of the links.
  1. $$('a[href^=http]').each(function(a) {
  2. if (window.location.hostname) {
  3. var hostname = window.location.hostname.replace("www.", "").toLowerCase();
  4. if (!a.get('href').contains(hostname)) {
  5. a.set({
  6. 'target': '_blank'
  7. });
  8. }
  9. }
  10. });

以上是关于带有mootools的XHTML有效外部链接的主要内容,如果未能解决你的问题,请参考以下文章

Mootools教程资源

如何使用 Mootools 操作表单

JavaScript [mootools]从点击的链接图像中删除onfocus虚线轮廓

Mootools:如何将点击功能绑定到以编程方式生成的元素

JS复习之JavaScript引入注意事项

UIWebView 打开外部链接