Home
> SharePoint 2007 > Open links (PDF document) in a new window
Open links (PDF document) in a new window
A client requests that the PDFs stored in a SharePoint document library need to be opened in new window instead of navigating the page away.
Thanks to the tip from Dustin Miller (http://www.sharepointblogs.com/dustin/archive/2006/02/03/supergeek-tip-open-off-site-links-in-a-new-window.aspx), I just modify the script to suit my needs.
<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[ i ]; //Note: Remove the spaces if you like
if (thisLink.href.indexOf(thisDomain) >=0 && thisLink.href.indexOf(".pdf") >=0) {
thisLink.target = "_blank";
//if (showMessage == 1) {
//thisLink.onclick = confirmNav;
//}
}
}
}
function confirmNav() {
return confirm(theMessage);
}
document.body.onload = updateLinks;
</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[ i ]; //Note: Remove the spaces if you like
if (thisLink.href.indexOf(thisDomain) >=0 && thisLink.href.indexOf(".pdf") >=0) {
thisLink.target = "_blank";
//if (showMessage == 1) {
//thisLink.onclick = confirmNav;
//}
}
}
}
function confirmNav() {
return confirm(theMessage);
}
document.body.onload = updateLinks;
</script>
Categories: SharePoint 2007
Comments (0)
Trackbacks (0)
Leave a comment
Trackback