1<!DOCTYPE html>
2<html>
3<head>
4</head>
5<body>
6<button onclick="tryit();">PDF</button>
7<script>
8 function tryit() {
9 var win = window.open('_blank');
10 downloadFile('/pdf', function(blob) {
11 var url = URL.createObjectURL(blob);
12 win.location = url;
13 });
14 }
15 function downloadFile(url, success) {
16 var xhr = new XMLHttpRequest();
17 xhr.open('GET', url, true);
18 xhr.setRequestHeader("Authorization", "Basic " + btoa("username:password"));
19 xhr.responseType = "blob";
20 xhr.onreadystatechange = function() {
21 if (xhr.readyState == 4) {
22 if (success) success(xhr.response);
23 }
24 };
25 xhr.send(null);
26 }
27
28</script>
29</body>
30</html>