SharePoint Printing Services, UrlAction, STSNavigate2 – Fixing "Invalid page URL:" in SharePoint 2010

After the eBay upgrade, I have decided that it is really easy to do SharePoint upgrades and thusly I'm doing another upgrade here in San Diego.  As part of the upgrade, you have to go through and analyze the 3rd party components that are installed and make sure they are going to work in 2010.  As I have learned, most are not SP2010 ready (OutlookPowerTools, older CorasWorks versions to name a few).  Some of them work with some tweaking.  That's what this blog post is about. 

This particular customer has the PrintingServices.wsp that allows a one click approach to printing pages and items.  What this product does is adds custom actions with a javascript url as the target of the click.  This works great in SharePoint 2007, but unfortunately, does not in SP2010.  The reason it does not work in SP2010 is that they do not simply pass the URL to the page anymore.  It is now wrapped by another javascript method called "STSNavigate2":

function STSNavigate2(evt, url)
{ULSxSy:;
    STSNavigate(url);
}

As you can see, it in turn calls function STSNavigate:

function STSNavigate(Url)
{ULSxSy:;
    if (window.location.search.indexOf("IsDlg=1") !=-1)
    {
        if (Url.indexOf("?") !=-1)
        {
            if (Url.match("&$") !="&")
            {
                Url=Url+"&IsDlg=1";
            }
            else
            {
                Url=Url+"IsDlg=1";
            }
        }
        else
        {
            Url=Url+"?IsDlg=1";
        }
    }
    if (isPortalTemplatePage(Url))
        window.top.location=STSPageUrlValidation(Url);
    else
        window.location=STSPageUrlValidation(Url);
}

STSNavigate in turn calls STSPageUrlvalidation:

function STSPageUrlValidation(url)
{ULSxSy:;
    return PageUrlValidation(url);
}

It then calls PageUrlValidation – THIS IS THE KEY PART:

function PageUrlValidation(url)
{ULSxSy:;
    if ((url.substr(0, 4)=="http") ||
        (url.substr(0, 1)=="/")     ||
        (url.indexOf(":")==-1))
    {
        return url;
    }
    else
    {
        var L_InvalidPageUrl_Text="Invalid page URL: ";
        alert(L_InvalidPageUrl_Text);
        return "";
    }
}

Notice that the only valid URLS start with http and contain a colon!!!!  Not sure the reasoning behind this "validation", but it breaks any custom actions that had a simple "javascript" call in them. 

You can fix this by changing the C:Program FilesCommon FilesMicrosoft SharedWeb Server Extensions14TEMPLATELAYOUTS1033Init.js file.  Note that this file has been minified (variable names reduced and spaces removed) and does not match the init.debug.js file.  Find the following text in the init.js file:

function PageUrlValidation(a){ULSA13:;if(a.substr(0,4)=="http"||a.substr(0,1)=="/"||a.indexOf(":")==-1)return a;else{var L_InvalidPageUrl_Text="Invalid page URL: ";alert(L_InvalidPageUrl_Text);return ""}}

Change it too:

function
PageUrlValidation(a){ULSA13:;if(a.toLowerCase().indexOf("javascript")>-1) return a; if(a.substr(0,4)=="http"||a.substr(0,1)=="/"||a.indexOf(":")==-1)return
a;else{var L_InvalidPageUrl_Text="Invalid page URL:
";alert(L_InvalidPageUrl_Text);return ""}}

This will then allow the older javascript links to work.  be sure to document the change as it would get overwrite with any service packs later.

Enjoy!
Chris