Bug Blog 6: Fix Broken File Downloads in 10gR3 (Part Trois)

*sigh*.  You’ve upgraded from ALUI to WCI 10gR3, and your Knowledge Directory links got all screwed up, didn’t they?  HTML files now throw an open/save dialog, some documents don’t open, you can’t copy links by just right-clicking them and choosing “Copy Shortcut”, and IE throws a popup blocker when you click a link in the Knowledge Directory, doesn’t it? 

You got the “To help protect your security, Internet Explorer blocked this site from downloading files to your computer” blues, huh?

I’ve tried creating a Plumtree Filter, and that worked pretty well, but not quite enough.

I’ve tried tweaking the Portal’s Javascript files, and THAT worked pretty well, but again, not quite well enough.

So, today, my friend’s, third time’s a charm:  rather than trying to fix this on the server side, we’re going to knock out this issue once and for all on the client side.  Check out those previous blog entries for a more detailed description of the problem, but basically, it’s because the portal uses a crazy convoluted way of opening documents via javascript. 

What we’re going to do today is stick some javascript in the footer of the page.  This JavaScript is going to simply find all those back-asswards links and replace them with NORMAL <a href=xxx target=_new> links.  If you add it to the footer of your site (specifically, the footer used for the KD, but the code is smart enough not to do anything if it’s on all pages), it should be able to take care of the rest.  Just make sure you add it to the Presentation Template and not the Content Item, because you-know-who only knows what a mess the out-of-the-box rich text editor is with javascript and adaptive tags.

The code after the break should be self-explanatory, but as always, if you’ve got a question or comment, feel free to post it here.  Also note that this code only fixes the download links; it doesn’t kill that “Open/Save” dialog box for things like HTML files.  For that you’ll still need the Plumtree Filter.

<pt:common.transformer pt:fixurl="off" xmlns:pt='http://www.plumtree.com/xmlschemas/ptui/'/>
       // only run in the KD
       if (document.title=="Directory")
              // get all links
              var anchors = document.links;
              for (x=0; x<anchors.length; x++) {

                     // get only those with an onclick event
                     onclickJS = anchors[x].onclick;
                     if (onclickJS != null)
                           onclickJS = "" + onclickJS;
                           var locCommonOpener = onclickJS.indexOf("PTCommonOpener.openInNewWindow");
                           var locpos = onclickJS.indexOf("currentWin.location");

                           // only process links that have the broken PTCommonOpener.openInNewWindow
                           if ((locpos>=0) &amp; &amp; (locCommonOpener>=0))
                                  // extract the URL from the broken onclick function
                                  var url = onclickJS.substr(locpos);
                                  var locstart = url.indexOf("'");
                                  if (locstart>=0)
                                         url = url.substr(locstart+1);
                                         var locend = url.indexOf("'");
                                         if (locend>=0)
                                                // update the URL by clearing the onclick and setting the URL to open in a new window
                                                url = url.substring(0,locend);
catch (err)
       // ignore errors

Tags: , , , ,

Leave a Reply