0

I have a shared path for a PDF file. if i paste the path in address bar,the file opens in all browser perfectly. Below code working fine in IE 8, but not in Chrome and Firefox

Code:

function openPDF(file) { window.open(file, '_blank'); } 

function linkFormatter(cellvalue, options, rowObject) {

    if ($.trim(cellvalue) == "" || cellvalue == null)
        return $.trim(cellvalue);
    else
        return '<a href="#" onclick="openPDF(\'file:' + rowObject["URL"].replace(/\\/g, "/") + cellvalue + '\')" >' + cellvalue + '</a>';
}

I am using this code in JQgrid to make link column.

Kindly help on this to make that working in all browsers.

Habeeb
  • 1,020
  • 16
  • 35

1 Answers1

1

I recommend to assign location.href inside of openPDF instead of usage window.open. Moreover I think better to use beforeSelectRow (or onCellSelect) to set click event handler. See the answer, this one, this one and other.

Community
  • 1
  • 1
Oleg
  • 220,925
  • 34
  • 403
  • 798
  • it is working in IE8 but not in Other browsers. my path looks like \\servername\foldername\name.pdf – Habeeb Dec 05 '14 at 06:52
  • @HbV2: Such URL is not real URL which will be used in production. Nevertherless you can paste such URL in web browser and see how it will be fixed. Fr example you will see `file://servername/foldername/name.pdf` in Chrome. So you can just use fixed syntax of the URL depend on the web browser which you use. – Oleg Dec 05 '14 at 07:48
  • Found the issue. Since browser is sand boxed it wont allow the to open local file. Thanks for your answer – Habeeb Dec 05 '14 at 12:01