Internet Explorer (IE) has limited support for certain modern web features, and using Blob URLs directly in the <embed> tag is one of those unsupported features. To display a PDF Blob URL in IE, you'll need to use a different approach.

Here's a workaround that should work for displaying a PDF Blob URL in IE:

  1. Create a Blob URL for the PDF: Before embedding the PDF, you need to create a Blob URL for the PDF content. Assuming you have the PDF content as a Blob, you can create a URL using URL.createObjectURL(blob).

    // Assuming 'pdfBlob' is the Blob containing the PDF content const pdfBlobUrl = URL.createObjectURL(pdfBlob);
  2. Detect if the browser is Internet Explorer: Since IE doesn't support Blob URLs directly, you need to detect if the user is using Internet Explorer. You can use feature detection or user-agent sniffing. For simplicity, I'll demonstrate user-agent sniffing here:

    function isInternetExplorer() { return /MSIE|Trident/.test(window.navigator.userAgent); }
  3. Embed the PDF using an <iframe> for IE: For IE, use an <iframe> instead of <embed> to display the PDF. For other browsers that support Blob URLs, you can use <embed>.

    <div id="pdfContainer"></div> <script> const pdfBlobUrl = URL.createObjectURL(pdfBlob); function isInternetExplorer() { return /MSIE|Trident/.test(window.navigator.userAgent); } const pdfContainer = document.getElementById("pdfContainer"); if (isInternetExplorer()) { // Use iframe for IE const iframe = document.createElement("iframe"); iframe.src = pdfBlobUrl; iframe.width = "100%"; iframe.height = "600px"; pdfContainer.appendChild(iframe); } else { // Use embed for other browsers const embed = document.createElement("embed"); embed.src = pdfBlobUrl; embed.type = "application/pdf"; embed.width = "100%"; embed.height = "600px"; pdfContainer.appendChild(embed); } </script>

This code will check if the user is using Internet Explorer and, if so, use an <iframe> element to display the PDF using the Blob URL. For other modern browsers, it will use the <embed> element as usual.

Please note that user-agent sniffing is generally not recommended due to its limitations and potential for inaccuracies. Feature detection is a more reliable approach, but implementing it might require additional checks and considerations.

Have questions or queries?
Get in Touch