It's been a while since my last post. I've been real busy, we lost a developer in January and have since hired a developer so the work load is starting to ease up. But I digress...
This post covers a little annoyance most of my customers have expressed, so I finally fixed it. The issue is that if there are links that lead from the WSS site, like to http://www.delphi-ts.com/, they want these links to open in a new window, instead of taking over their current window. These links might be located in the Links lists, quick launch or the top link bar. I also applied the same to PDFs. For some reason, users can never pick up on the idea that the PDF is on the same window, so they close it instead of pressing back.
I thought about a few different approaches to this issue and decided upon the following. Basically, this javascript loops through all links on the page and if the link is not looking at the current site's name, then it'll add a target location to be the new window. Simply copy this script to the bottom of your master page, right above the closing BODY tag. You can also add this to the default master page so that all new sites will have it as well. Look in the global folder in templates, default.master is there and mwsdefault.master is there (used for workspaces).
{
var links; links = document.getElementsByTagName("A") // returns all objects on the page that are A tags ()
var url = '://' + window.location.hostname // get the current website name, and i add :// to make sure we're looking at the right name in the URL, rules out http://www.google.com/site:wss.domain.com
url = url.toLowerCase() // lowercase everything to compare apples to apples
for(var i=0; i < links.length; i++) // loop through all return A objects
{
var link = links[i] // assign the link object to another variable for easier managability
var linkHref = link.href.toLowerCase() // lower case it
if(linkHref.indexOf(url) < 0 && linkHref.indexOf('javascript:') < 0){){ // check to see if this A object has this domain in it and make sure it's not a javascript call
link.target = '_blank' // change the target to be in the new window
}
if(linkHref.indexOf('.pdf') > 0){ // check to see if this is a PDF
link.target = '_blank' // change the target to be in the new window
}
}
}
Put the closing script tag here, this blog editor doesn't allow the forward slash...
Please let me know if you use this, I love to know when I can help! Also, if you have a better solution, let me know! Enjoy!