10

Earlier following code would open a pdf file in a new window.

var pdfDocument = "data:application/pdf;base64," + data;
window.open(pdfDocument);

After updating chrome, it seems to stop working. Appranely, chrome removed Top-frame navigations to data URLs.

How can I solve my issue now? I need to open this pdf in a new window. Any help will be appreciated.

UPDATE

Solved it using iFrame. Thanks to Pedro for giving me the idea.

<iframe id="ManualFrame"
        frameborder="0"
        style="border:0"
        allowfullscreen>
</iframe>

<script>
    $(function () {
        setManualFrame();
    });

    function setManualFrame() {
        $("#ManualFrame").attr("height", screen.height);
        $("#ManualFrame").attr("width", screen.width);
        $("#ManualFrame").attr("src", "data:application/pdf;base64," + '@ViewBag.pdf_base64_data');
    }
</script>
Lonely Planeteer
  • 389
  • 1
  • 5
  • 21
  • Have you read this question from a couple of days ago https://stackoverflow.com/questions/45493234/jspdf-not-allowed-to-navigate-top-frame-to-data-url - oops, you posted an **ANSWER** there! That wont last long – Jaromanda X Aug 10 '17 at 01:56
  • By the way, this behaviour is coming to Firefox very soon too - so you'd better figure out how to use iframe's for this – Jaromanda X Aug 10 '17 at 02:02
  • I am not familiar with iFrame. Can you help on this regard? – Lonely Planeteer Aug 10 '17 at 02:04
  • Sure, MDN has documentation for all the elements, including [iframe](https://developer.mozilla.org/en/docs/Web/HTML/Element/iframe) – Jaromanda X Aug 10 '17 at 02:04
  • Thank you for this answer but can you tell me how I can download the pdf from the iframe? Is it possible? – Pallavi Prasad Aug 14 '17 at 15:49
  • @PallaviPrasad: If it's a pdf, it should already have download option. Look [here](http://imgur.com/a/MFfRl) for the idea. – Lonely Planeteer Aug 14 '17 at 23:02
  • @LonelyPlaneteer When I click on download it has no action here, you did something else to download? Found a question with same issue here: https://stackoverflow.com/questions/50775868/new-tab-with-pdf-download-button-not-working-on-chrome – Gustavo Graupner Jun 09 '18 at 16:11
  • @GustavoGraupner, I have not done anything else. – Lonely Planeteer Jun 12 '18 at 03:45

1 Answers1

4

Deprecations and Removals in Chrome 60:

Remove content-initiated top frame navigations to data URLs

Because of their unfamiliarity to non-technical browser users, we're increasingly seeing the data: scheme being used in spoofing and phishing attacks. To prevent this, we're blocking web pages from loading data: URLs in the top frame. This applies to tags, window.open, window.location and similar mechanisms. The data: scheme will still work for resources loaded by a page.

This feature was deprecated in Chrome 58 and is now removed.

Source: https://developers.google.com/web/updates/2017/06/chrome-60-deprecations

Community
  • 1
  • 1
  • 6
    Hello, this seems more of a comment not an answer. And, the user seems to be aware of the reason that the issue happens. – tima Aug 18 '17 at 01:05
  • 1
    the question it self also have answer with update but not detailed description of cause of issue. I only want to share description. – Cafer Can Arslan Aug 18 '17 at 12:24
  • 6
    I understand, but a description of the issue is not an answer – tima Aug 18 '17 at 12:26
  • Even a browser Ctrl-R refresh doesn't work. Had to a bug there. – Pacerier Nov 23 '17 at 08:52
  • Wish browser makers would enact policy: every new security restriction must be accompanied by a user-controlled override. Some of us want to use the browser as a portable O/S and not have to shove crap to the (hey look, less secure!) server just to work around however-well-intentioned security hobbles. – Ron Burk Dec 06 '17 at 01:20