使用REL External而不是弃用的Target属性打开新窗口
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了使用REL External而不是弃用的Target属性打开新窗口相关的知识,希望对你有一定的参考价值。
Excellent Script for opening new windows from links while adhering to modern html/XHTML standards. Simple put rel="nofollow" in the anchor and link to the script within the HEAD.I prefer to remove the text that states the link opens in an external windows. To do that, simply change this part of the last line from this:
("rel","external"," (external website, opens in a new window)")
to this:
("rel","external","")
/* JSTarget function by Roger Johansson, www.456bereastreet.com */ var JSTarget = { init: function(att,val,warning) { if (document.getElementById && document.createElement && document.appendChild) { var strAtt = ((typeof att == 'undefined') || (att == null)) ? 'class' : att; var strVal = ((typeof val == 'undefined') || (val == null)) ? 'non-html' : val; var strWarning = ((typeof warning == 'undefined') || (warning == null)) ? ' (opens in a new window)' : warning; var oWarning; var arrLinks = document.getElementsByTagName('a'); var oLink; var oRegExp = new RegExp("(^|\s)" + strVal + "(\s|$)"); for (var i = 0; i < arrLinks.length; i++) { oLink = arrLinks[i]; if ((strAtt == 'class') && (oRegExp.test(oLink.className)) || (oRegExp.test(oLink.getAttribute(strAtt)))) { oWarning = document.createElement("em"); oWarning.appendChild(document.createTextNode(strWarning)); oLink.appendChild(oWarning); oLink.onclick = JSTarget.openWin; } } oWarning = null; } }, openWin: function(e) { var event = (!e) ? window.event : e; if (event.shiftKey || event.altKey || event.ctrlKey || event.metaKey) return true; else { var oWin = window.open(this.getAttribute('href'), '_blank'); if (oWin) { if (oWin.focus) oWin.focus(); return false; } oWin = null; return true; } }, /* addEvent function from http://www.quirksmode.org/blog/archives/2005/10/_and_the_winner_1.html */ addEvent: function(obj, type, fn) { if (obj.addEventListener) obj.addEventListener(type, fn, false); else if (obj.attachEvent) { obj["e"+type+fn] = fn; obj[type+fn] = function() {obj["e"+type+fn]( window.event );} obj.attachEvent("on"+type, obj[type+fn]); } } }; JSTarget.addEvent(window, 'load', function(){JSTarget.init("rel","external"," (external website, opens in a new window)");});
以上是关于使用REL External而不是弃用的Target属性打开新窗口的主要内容,如果未能解决你的问题,请参考以下文章
外部链接:当使用rel =“external”或rel =“nofollow”时?
链接属性rel=’external’rel=’nofollow’rel=’external nofollow’三种写法的区别
使用Prototype将Rel External更改为Target Blank
Cake 1.3 中有任何好的/简单的 Ajax 示例而不使用已弃用的助手?