1

I am receiving the location of a pdf document in angular, and I cant get it to consistently download.

It works on my home laptop, but not whilst at work. Code below

RenderService.document('document.pdf', spec).then(function(pdfLocation) {
    $window.location = pdfLocation;
});

Works in Chrome on Ubuntu at home, not on the same set up at work. Does anyone know any reason why the operation of '$window.location' wouldn't be idempotent?

Update: Also works on FF on my work machine, just not Chrome

Ben Taliadoros
  • 7,003
  • 15
  • 60
  • 97

2 Answers2

1

This mostly happends if you have some third part software installed or the browser security is configured as to high. Check for addblocker & antivir software on your machine and also check the security configuration in your browser. Ensure that your pdf location is based on HTTPS if your application is running on HTTPS.

For Chrome & Safari try to set your window.location.href property instead of window.location. This should work for all browser so.

RenderService.document('document.pdf', spec).then(function(pdfLocation) {
    window.location.href = pdfLocation;
    return false;
});

Here is a plnkr demo which does run well in chrome.

lin
  • 17,956
  • 4
  • 59
  • 83
  • The $widow.location.href didn't work, but the error does go away when I deselect "Protect you and your device from dangerous sites" from advanced settings. (I don't want to mark this as correct as it will confuse people passing by to the actual issue here) – Ben Taliadoros Mar 29 '17 at 09:56
  • Is your `pdfLocation` holding a full qualified URL like `http://domain/download.pdf`? Try is one time with `window` instead of AngularJS instance `$window`. I'll create a fiddle for testing .. can't belive it =) – lin Mar 29 '17 at 09:57
  • $window.location works in your plunker when i change it, and both my site and the pdf are on https. so its neither of those. I also tried window instead of $window and it's not that either. My url is "https://somelocalhostproxy:8443/etc/document.pdf", I'm guessing Chrome is blocking it as it knows it's local – Ben Taliadoros Mar 29 '17 at 10:34
  • Crazy crazy, it should work for local domains too. Could you add `return false;` as provided in my answer? – lin Mar 29 '17 at 10:37
  • I'm afraid it made no difference – Ben Taliadoros Mar 29 '17 at 10:41
  • Yea, that's what I thought =( – lin Mar 29 '17 at 10:42
  • Does it work if you enter a TEST PDF url like `https://www.suec.de/Download/PDF/Test.pdf` ? – lin Mar 29 '17 at 10:43
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/139351/discussion-between-lin-and-ben-taliadoros). – lin Mar 29 '17 at 10:43
0

Thanks to @lin I realised the issue was chrome blocking my download due to the advanced security option in Chrome: "Protect you and your device from dangerous sites"

I'm not sure how to get around it yet, and will update this answer if I find a solution

Ben Taliadoros
  • 7,003
  • 15
  • 60
  • 97