Javascript examples for DOM HTML Element:Anchor
Change <a> to target="_blank" in <a> click event
<html> <head> <meta name="viewport" content="width=device-width, initial-scale=1"> <script type="text/javascript"> window.onload=function(){/*from ww w. ja v a 2 s. c o m*/ document.addEventListener("click", function (e) { if (e.target.tagName == "A" && !e.target.hasAttribute("target")) { e.target.setAttribute("target", "_blank"); } }); } </script> </head> <body> <a href="http://java2s.com">test</a> </body> </html>