I know I said I'd do these every week, but I might not be able to post this one next week, and I just can't sit on it any longer.
Many people want to modify their links list (really, just the links web part on the default.aspx of a site) so that links open in a new window. Typically, what they REALLY want is only off-site links opening in a new window. Up until now, you've had to modify the site definition, or (heh) tell users to hold the SHIFT key down.
Why not throw a Content Editor Web Part on the page, and use this code sample? It will modify ALL links that leave the current domain (except JavaScript links, don't want to break the “Help” at the top of a SharePoint page) to open in a new window and, if you choose, will show a warning first. Here's the code:
<script>
var theLinks = document.links;
var thisDomain = window.location.hostname;
// Edit "theMessage" to your liking
var theMessage = "You are now leaving " + thisDomain + ". The content of the requested web site is outside our control. The requested web page will open in a new window. You may click \"Cancel\" to stop loading the requested page. You may need to hold your CTRL key down when pressing \"OK\" to bypass your pop-up blocking software.";
// Change "showMessage" to 0 if you don't want the warning to pop up when navigating to external sites.
var showMessage = 1;
function updateLinks() {
for (i=0; i < theLinks.length; i++) {
var thisLink = theLinks
;
if (thisLink.href.indexOf(thisDomain) == -1 && thisLink.href.indexOf("javascript") == -1) {
thisLink.target = "_blank";
if (showMessage == 1) {
thisLink.onclick = confirmNav;
}
}
}
}
function confirmNav() {
return confirm(theMessage);
}
document.body.onload = updateLinks;
</script>