JavaScript redirect to local file

Posted on 2004-11-08
Last Modified: 2009-07-29
Currently there is an application running that was written in house. In the application there is a JavaScript redirect that will open a PDF file off the local machine, the code is below.

The code worked great on all platforms until XP SP2 came along and then it stopped working and we get a "page cannot be displayed" error. We have tried turning off the pop-up blocker and that wasn't it, so any help would be appreciated.

Can anyoen help with what setting we need to change in IE to get this to work again? Here is the code.

 * buildMidwestActivityReportLinkUrl
 * JavaScript function that builds the Midwest Activity Report link URL with the
 * parameters required for the servlet.
 * Author: Janardan Kortikere
function buildMidwestActivityReportLinkUrl()
      var sortDirectionsList = document.midwestActivitySortFilterForm.sortDirectionsList.value;
      var hiddenFilterProjectStatusId = document.midwestActivitySortFilterForm.hiddenFilterProjectStatusId.value;
      var hiddenFilterBuildingCode = document.midwestActivitySortFilterForm.hiddenFilterBuildingCode.value;
      var filterDoneByDateFromOffset = document.midwestActivitySortFilterForm.filterDoneByDateFromOffset.value;
      var filterDoneByDateToOffset = document.midwestActivitySortFilterForm.filterDoneByDateToOffset.value;
      var filterDoneByTimeFrom = document.midwestActivitySortFilterForm.filterDoneByTimeFrom.value;
      var filterDoneByTimeTo = document.midwestActivitySortFilterForm.filterDoneByTimeTo.value;

      var midwestActivityReportLink =
            '<%= UrlBuilder.getServletRoot() %><%= ApplicationConstants.SERVLET_PRINT_MIDWEST_ACTIVITY_REPORT %>'
            + '?<%= ApplicationConstants.ACTION %>=<%= ApplicationConstants.ACTION_PREVIEW %>'
            + '&sortDirectionsList=' + sortDirectionsList
            + '&hiddenFilterProjectStatusId=' + hiddenFilterProjectStatusId
            + '&hiddenFilterBuildingCode=' + hiddenFilterBuildingCode
            + '&filterDoneByDateFromOffset=' + filterDoneByDateFromOffset
            + '&filterDoneByDateToOffset=' + filterDoneByDateToOffset
            + '&filterDoneByTimeFrom=' + filterDoneByTimeFrom
            + '&filterDoneByTimeTo=' + filterDoneByTimeTo
            + '&sortField1=' + document.midwestActivitySortFilterForm.sortField1.value
            + '&sortField2=' + document.midwestActivitySortFilterForm.sortField2.value
            + '&sortField3=' + document.midwestActivitySortFilterForm.sortField3.value
            + '&sortField4=' + document.midwestActivitySortFilterForm.sortField4.value
            + '&sortField5=' + document.midwestActivitySortFilterForm.sortField5.value;
      return midwestActivityReportLink;
 * showMidwestActivityReportInNewWindow
 * JavaScript function that displays the Midwest Activity Report in a new window.
 * Author: Janardan Kortikere
function showMidwestActivityReportInNewWindow()
      midwestActivityReportWin.document.write("<head><title>Midwest Activity Report<\/title><\/head>");
      midwestActivityReportWin.document.write('<h1>' + 'Retrieving report data .... please wait' + '</h1>');
      setTimeout('midwestActivityReportWin.location.href=newURL;', 1000);      
Question by:mt_100
    1 Comment
    LVL 49

    Accepted Solution

    This is because the file:// domain is another domain than the http:// domain. Therefor SP2 does not allow you to change a "online" document to "local" href.

    A solution is to have a frame/window with href file:// and then change it using javascript:

    <iframe src="file://" id="midwestActivityReportWin"></iframe>

    midwestActivityReportWin.location.href = "file://localfile";

    Regards, and goodluch,


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Training Course: Adobe Dreamweaver CC 2015

    Adobe Dreamweaver Creative Cloud is used by web designers and front-end developers and allows you to visualize your site in real-time as you code. This course covers exam objectives for the Adobe Certified Associate (ACA) certification.

    Today I would like to talk about localizing (Internationalization) JavaScript applications. Introduction When creating an application that is going to be used by many people around the globe, it is important to remember that not everyone speak…
    I've been trying to accomplish this for a while and it just struck me yesterday how to accomplish this task. I have done searches all over the internet looking for ways to email pages from my applications and finally I have done it!!! Every single s…
    The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
    The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

    794 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    16 Experts available now in Live!

    Get 1:1 Help Now