Line-by-line explanation of the "External Links Script" by Bill Brown Presented at Perishable Press @ https://perishablepress.com/press/2009/01/20/targeting-external-links-intelligently/ 01. Open a new self-invoking anonymous function to encapsulate this script and prevent collisions. 02. Define the extAnchorTarget function. 03. Just instantiating some variables. 04. My prompt message to ask the user what to do with the external anchor. 05. Continuation of 4 because I try to keep my scripts from exceeding 80 characters of width. Obsessive, I know. 06. Tries to set the usropt variable to a form value, or to zero if it can't find the form element. 07. Ensuring our value is an integer in preparation of the upcoming switch case statement. 08. The aforementioned switch case statement. 09. If the user has opted to open all external links in a new window... 10. ...we simply set the target to "_blank"... 11. ...and break out of the statement. 12. If the user has opted to open all external links in this window... 13. ...we just set the target to "_self"... 14. ...and break out of our statement. 15. If the user hasn't changed anything, or selected to be asked each time... 16. ...or if we can't find the form input... 17. ...we use the browser's built-in confirm function to get their answer... 18. ...and set the target to "_self" if they clicked "Cancel" or to "_blank" if they clicked "OK"... 19. ...and the break out of the statement. 20. Just closing our switch case statement. 21. Returning true so that the action can continue, like a Van Damme movie. 22. And now we close our extAnchorTarget function. 23. Here we're defining our labelAnchors function, which is actually the first function called when the document is ready. 24. This line assumes the document.domain property contains the domain name of our website, chunks it on the dot characters, reverses the array and assigns it to the winhome variable. 25. Now, we join the first part of the winhome array (assuming a top level domain extension) and the second part of the winhome array, which one assumes is the base name of our domain. 26. A little jQuery selector action here, and then iterate through the elements... 27. Take the href attribute from the anchor, chunk it on the forward slashes, grab the second part, chunk it on the dots, reverse it and assign the value to the lnkhome variable. 28. Like with the winhome variable, we can now rejoin the first part of the lnkhome array and the second part of the lnkhome array, which we assume is the base of the domain for this link. 29. Simple matching check of the two variables will tell us if this is an off-site resource. 30. If the two variables don't match, give it the "external" class... 31. ...and call the extAnchorTarget function whenever this element is clicked. 32. If they do match... 33. ...we class it as "internal" (not really necessary) and continue. 34. Wrapping up our if else statement... 35. Closing the jQuery selector iteration loop... 36. ...you don't have to go home... butcha can't stay here. Closing the labelAnchors function. 37. jQuery's DOM ready shortcut syntax magic... 38. ...calling the labelAnchors function when the document is ready... 39. ...closing that... 40. ...and then close and invoke the anonymous function.