Andy Herman
Andy Herman

Reputation: 53

Opening data:text/plain window in chrome showing up blank

The current function is working and has been working for years, however within the last 3 weeks suddenly users on Chrome cannot access the plain text document, but is still working on other browsers.

Basically the function runs like this:

<a class="modo-link" target="_blank" data-modo="4%20Aether%20Hub%0A4%20Botanical%20Sanctum%0A1%20Blooming%20Marsh%0A3%20Forest%0A1%20Island%0A2%20Mountain%0A3%20Rootbound%20Crag%0A1%20Sheltered%20Thicket%0A2%20Spirebluff%20Canal%0A1%20Swamp%0A4%20Bristling%20Hydra%0A3%20Glorybringer%0A4%20Longtusk%20Cub%0A4%20Rogue%20Refiner%0A4%20Servant%20of%20the%20Conduit%0A2%20The%20Scarab%20God%0A4%20Whirler%20Virtuoso%0A2%20Abrade%0A4%20Attune%20with%20Aether%0A2%20Essence%20Scatter%0A4%20Harnessed%20Lightning%0A1%20Magma%20Spray%0A%0ASideboard%0A2%20Cartouche%20of%20Ambition%0A2%20Chandra's%20Defeat%0A1%20Confiscation%20Coup%0A3%20Negate%0A1%20Supreme%20Will%0A2%20Spell%20Pierce%0A1%20Hour%20of%20Glory%0A1%20Struggle%2FSurvive%0A2%20Vizier%20of%20Many%20Faces"><img src="https://227rsi2stdr53e3wto2skssd7xe-wpengine.netdna-ssl.com/wp-content/plugins/crystal-catalog-helper/assets/img/modologo.png"></a>

$('.modo-link').on('click', function() {
     var win = window.open('data:text/plain;charset=utf-8,' + $(this).attr('data-modo'), '_blank');
     win.focus();
});

Example is here: https://www.channelfireball.com/articles/the-return-of-nationals/

Just find the "Temur Black" deck list and click the icon above the image example: Deckilst icon

I can't seem to figure out what is causing it in Chrome to open a blank window when it used to work fine, could it be an SSL thing?

Thanks

Upvotes: 3

Views: 2672

Answers (3)

wersimmon
wersimmon

Reputation: 2869

The Chromium team intentionally deprecated and removed the ability to open data URLs. This change appears to be active as of Chrome 61.

Upvotes: 3

Andy Herman
Andy Herman

Reputation: 53

I ended up getting it to work using Ahmed's method but I had to decode the URI and replace the breaks with <br>, I think it will work fine.

var win = window.open(); 
win.document.write(decodeURIComponent($(this).attr('data-modo')).replace(/(?:\r\n|\r|\n)/g, '<br/>'));
win.focus();

But if anyone has another answer to keep it using text let me know.

Upvotes: 2

Ahmed Elsayed
Ahmed Elsayed

Reputation: 31

It's not working on chrome but you can use alternative solution like:

var w = window.open("");
w.document.write('Your Text Here'); 

It's working on all major browsers.

Upvotes: 1

Related Questions