Link to data url doesn't open until I hit return in url bar

Viewed 489

I have a chunk of html that I want to render in another window when somebody clicks on a link (embedded in some text that comes from the back-end) in the browser. So in the Java back-end, I base64 encode it and put it into the text that's being sent to the front end:

String encoded = DatatypeConverter.printBase64Binary(resourceRecord.getHtml().getBytes());
                    a.attr("href", "data:text/html;base64," + encoded)
                            .attr("target", "_blank")
                            .attr("rel", "nofollow");

And when the text is rendered, I see a blue underlined link that looks like this in the web inspector: enter image description here

So far so good. Unfortunately, when I click the link, it just opened a new blank tab. In both Firefox and Chrome, if I click on the address bar in that new tab, it shows the data url in the address bar, and if I hit return the expected html is rendered.

How can I make that html actually render without the "click in the address bar and hit return" step? Or is it even possible?

Update Added a Content Security Policy with navigate-to 'self' https: http: data: and that didn't help. I also tried not base64 encoding because I read one site that said that Chrome was restricting top level data urls only for base64 encoding, but that didn't help, and other sources talked about restricting it for all data urls. Every solution I saw involved opening a window and doing a write into it, rather than using an <a> tag, so I'm coming to the conclusion that this just isn't possible.

0 Answers
Related