20

We're getting the following message from Chrome when downloading (or attempting to download) a pdf in our mobile web application.

"Warning: Something's not right here!... The site you are trying to access is acting strangely, and Chrome is unable to verify that the URL is correct."

This is working fine in Safari and essentially we are doing this.

  1. On load do a call to verify that the document that we want to show is OK.
    • if the document is not ok message the user and then close the tab
  2. Direct the tab to navigate to an address which downloads the PDF.

Without posting too much code the Javascript is something like this:

DoRequest ("print_report",
           "VALIDATE",
           mycallback);

function mycallback (data,error) {

    var h_href = "";
    var h_widget = "";

    if(error == true) {
        window.close(); 
        return;
    }    

    h_href = GenerateHREF( "print_report", "PRINT" );

    window.location.href = h_href;        
}

The URL provided by GenerateHREF is for the same originating site and is relative to the original.
the mime type is set to application/pdf. The content-disposition is set to inline. I've tried setting the content-size header as well but it doesn't seem to have any effect.

Content-Disposition: attachment; filename="pp66.26.pdf"
Content-Length: 31706
Content-Type: application/pdf

I'm missing something ... just what?

DuStorm
  • 293
  • 2
  • 7
  • I'm currently guessing that it is related to popup blocking, by adding a user interaction immediately before the navigation Chrome starts displaying the link. – DuStorm Oct 31 '12 at 14:27
  • While not specifically the answer remote debugging for ios Chrome would be of help. http://stackoverflow.com/questions/11262236/chrome-for-ios-remote-debugger – DuStorm Oct 31 '12 at 14:46
  • I think this is a chrome bugg, see this link: http://code.google.com/p/chromium/issues/detail?id=85549 , something about Content-Length. – joao Oct 04 '13 at 10:18

3 Answers3

1

Try to parse document to base64 and added to your document or iframe.

    function getAsyncBase64(fileName, callBack){
        var xhr = new XMLHttpRequest();
        xhr.open('GET', fileName, true);
        xhr.responseType = 'arraybuffer';
        xhr.onload = function (e) {
        if (this.status == 200) {
            var uInt8Array = new Uint8Array(this.response || this.responseText);
            var i = uInt8Array.length;
            var binaryString = new Array(i);
            while (i--) {
                binaryString[i] = String.fromCharCode(uInt8Array[i]);
            }
            var dataBinary = binaryString.join('');
            var data64 = window.btoa(dataBinary);
            callback(data64);                
        }
        xhr.send();
    };
    function callback(base64){
        window.open(base64, "_blank");
        //or
        iframe.src = "data:application/pdf;base64,"+ base64;
    };

    getAsyncBase64(url,callback);
sendler
  • 41
  • 3
0

If it's a popup/download issue you might be able to show it using an iframe?

<iframe src="downloads/report.pdf"></iframe>
Kim T
  • 5,770
  • 1
  • 52
  • 79
0

I also think that popup behavior is probably high on the list of suspects (specifically the window.close(); line seems pretty suspicious especially if the popup is blocked by the user).

However, since the ultimate goal is to download the file, you could try changing the response headers to

Content-Disposition: attachment; filename="pp66.26.pdf"
Content-Length: 31706
Content-Type: applicaton/octet-stream

or you could try forcing all pdfs in a particular folder to force a download via .htaccess file, then just linking to them via the location.href you are using:

<FilesMatch "\.pdf$">
ForceType applicaton/octet-stream
Header set Content-Disposition attachment
</FilesMatch>
srussking
  • 346
  • 4
  • 10