»
Tiếng AnhTiếng PhápTiếng Việt

In - Mở liên kết trong cửa sổ mới - JavaScriptBank.com

Phiên bản đầy đủ: jsB@nk » Liên kết » Mở liên kết trong cửa sổ mới
URL: https://www.javascriptbank.com/link-enhancer-index.html

Mở liên kết trong cửa sổ mới © JavaScriptBank.comNếu sử dụng đoạn mã này trên trang web của bạn thì các liên kết dẫn đến các tài nguyên bên ngoài sẽ tự động được mở trong một cửa sổ/thẻ mới; mà bạn không cần phải thêm bất cứ thứ gì trong liên kết.Ngoài ra, đoạn mã còn áp dụng các kiểu (style) cho liên kết để người dùng có thể nhận biết nó dẫn đến các trang ngoài.

Phiên bản đầy đủ: jsB@nk » Liên kết » Mở liên kết trong cửa sổ mới
URL: https://www.javascriptbank.com/link-enhancer-index.html



CSS
<style type="text/css">.link_ext { height: 20px; background: url(link_ext.gif) no-repeat right 4px; padding: 0 13px 0 0;}</style><!--    This script downloaded from www.JavaScriptBank.com    Come to view and download over 2000+ free javascript at www.JavaScriptBank.com-->


JavaScript
<script type="text/javascript">/* -----------------------------------------------   Link Enhancer - v.1.1   (c) 2007 www.haan.net   contact: jeroen@haan.net   You may use this script but please leave the credits on top intact.   Please inform us of any improvements made.   When useful we will add your credits.  ------------------------------------------------ */  // Give the outbound links a blank target and their own style// and optional the inbound too or vise versa// It will leave the mailto alone and skip anchor tags without the href attributefunction enhanceLinks() { var links = document.getElementsByTagName("a"); var thisDomain = document.domain.split('www.'); var thisDomain = (thisDomain[1]) ? thisDomain[1] : document.domain ; for (var i = 0; i < links.length; i++) {  if(links[i].href.indexOf(thisDomain) == -1 && links[i].href != '') {   links[i].target = '_blank';   links[i].className = 'link_ext';  }// or else do this too if you like// else // {//links[i].target = '_self';//links[i].className = 'link_int';// }}}// Multiple onload function created by: Simon Willison// http://simon.incutio.com/archive/2004/05/26/addLoadEventfunction addLoadEvent(func) {  var oldonload = window.onload;  if (typeof window.onload != 'function') {    window.onload = func;  } else {    window.onload = function() {      if (oldonload) {        oldonload();      }      func();    }  }}addLoadEvent(function() {  enhanceLinks();});</script><!--    This script downloaded from www.JavaScriptBank.com    Come to view and download over 2000+ free javascript at www.JavaScriptBank.com-->


HTML
<ul>  <li><a href="http://www.javascriptbank.com/">Web Developer</a></li>  <li><a href="http://javascriptbank.com/">JavaScript Source</a></li></ul><!--    This script downloaded from www.JavaScriptBank.com    Come to view and download over 2000+ free javascript at www.JavaScriptBank.com-->


Files
http://javascriptbank.com/javascript/link/Link_Enhancer/link_ext.gif