Jump to content

enzzzzzzzz

Members
  • Posts

    5
  • Joined

  • Last visited

Posts posted by enzzzzzzzz

  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><title>OpenLinkInAnotherWindow</title><script type="text/javascript">function addEvent (elm,evType,fn,useCapture) { if (elm.addEventListener) { elm.addEventListener(evType,fn,useCapture); return true; } else if (elm.attachEvent) { var r=elm.attachEvent('on'+evType,fn); return r; };else { elm['on'+evType] =fn; }}function handleLink(e) { var el; if (window.event && window.event.srcElement) el=window.event.srcElement; if (e && e.target) el=e.target; if (!el) return; while (el.nodeName.toLowerCase() != 'a' && el.nodeName.toLowerCase() !='body') el=el.parentNode; if (document.getElementById('newwin') && document.getElementById('newwin').checked) { window.open(el.href);//open new window if (window.event) { window.event.cancelBubble=true; window.event.returnValue=false; }//stop bubling for IE if (e && e.stopPropagation && e.preventDefault) { e.stopPropagation(); e.preventDefault(); }//stop bubling for other browsers }}function cancelClick { if (document.getElementById('newwin') && document.getElementById('newwin').checked) { return false; } return true;}//this is for safarifunction addListeners() { if (!document.getElementById) return; var all_links = document.getElementsByTagName('a'); for (var i = 0; i<all_links.length; i++) { addEvent(all_links,'click',handleLink, false); all_links.onclick=cancelClick; }}addEvent(window,'load',addListeners,false);</script><style type="text/css">form { float:right; width:25em; height:5em; border:1px solid blue; padding:1em; }</style></head><body><h1>SmartLinks</h1><form action=""><p><label for="newwin">Open Links In New Window?<input type="checkbox" id="newwin" /></label></p></form><p> This page contains several links, such as <a href="http://www.sitepoint.com/">sitepoint</a>,<a href="http://www.yahoo.com">yahoo!</a>,<a href="http://www.google.com/">Google</a>.These links should ordinarily open in the same window when clicked, unless the checkbox is checked; this will make them open in a new window.</p></body></html>

×
×
  • Create New...