Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

get authorization header javascript in my page

<!DOCTYPE html>
<html>
<head>
</head>
<body>
<button onclick="tryit();">PDF</button>
<script>
    function tryit() {
        var win = window.open('_blank');
        downloadFile('/pdf', function(blob) {
            var url = URL.createObjectURL(blob);
            win.location = url;
        });
    }
    function downloadFile(url, success) {
        var xhr = new XMLHttpRequest();
        xhr.open('GET', url, true);
        xhr.setRequestHeader("Authorization", "Basic " + btoa("username:password"));
        xhr.responseType = "blob";
        xhr.onreadystatechange = function() {
            if (xhr.readyState == 4) {
                if (success) success(xhr.response);
            }
        };
        xhr.send(null);
    }

</script>
</body>
</html>
Comment

PREVIOUS NEXT
Code Example
Javascript :: How to get all input fields inside div with JavaScript 
Javascript :: loop in react depending on number 
Javascript :: how to change checkbox state in jquery 
Javascript :: how to get href value of anchor tag in jquery in list 
Javascript :: javascript video feed 
Javascript :: navigation.openDrawer is not a function react native 
Javascript :: datatable giving default width to colums 
Javascript :: javascript include js file 
Javascript :: invert binary tree javascript 
Javascript :: reverse 179 in javascript 
Javascript :: getting form values in javascript 
Javascript :: capitalize first letter after character javascript 
Javascript :: javascript name capitalization 
Javascript :: print placeholder value javascript 
Javascript :: hwo to cehck req header in js 
Javascript :: fullcalendar v5 time format am/pm 
Javascript :: process.env in nextjs 
Javascript :: vue watch child property 
Javascript :: check for alphabetic string in javascript 
Javascript :: share link to whatsapp javascript 
Javascript :: login page link shopify 
Javascript :: regex match line that does not contain string 
Javascript :: javascript math.pow 
Javascript :: copy to clipboard javascript dom 
Javascript :: Factorial multiplication in javascript 
Javascript :: regex to ignore white spaces js 
Javascript :: how to display api data in html 
Javascript :: factorial javascript 
Javascript :: useeffect with cleanup 
Javascript :: datatables get all rows 
ADD CONTENT
Topic
Content
Source link
Name
1+6 =