   1. /*
   2. Create the new window
   3. */
   4. function openInNewWindow() {
   5. // Change "_blank" to something like "newWindow" to load all links in the same new window
   6. var newWindow = window.open(this.getAttribute('href'), '_blank');
   7. newWindow.focus();
   8. return false;
   9. }
  10.
  11. /*
  12. Add the openInNewWindow function to the onclick event of links with a class name of "non-html"
  13. */
  14. function getNewWindowLinks() {
  15. // Check that the browser is DOM compliant
  16. if (document.getElementById && document.createElement && document.appendChild) {
  17. // Change this to the text you want to use to alert the user that a new window will be opened
  18. var strNewWindowAlert = " (opens in a new window)";
  19. // Find all links
  20. var objWarningText;
  21. var strWarningText;
  22. var link;
  23. var links = document.getElementsByTagName('a');
  24. for (var i = 0; i < links.length; i++) {
  25. link = links[i];
  26. // Find all links with a class name of "non-html"
  27. if (/\bnon\-html\b/.exec(link.className)) {
  28. // Create an em element containing the new window warning text and insert it after the link text
  29. objWarningText = document.createElement("em");
  30. strWarningText = document.createTextNode(strNewWindowAlert);
  31. objWarningText.appendChild(strWarningText);
  32. link.appendChild(objWarningText);
  33. link.onclick = openInNewWindow;
  34. }
  35. }
  36. objWarningText = null;
  37. }
  38. }
