【问题标题】:Opening data:text/plain window in chrome showing up blank打开数据:chrome中的文本/普通窗口显示为空白
【发布时间】:2017-10-18 19:44:42
【问题描述】:

当前功能正在运行,并且已经运行多年,但是在过去 3 周内,Chrome 上的用户突然无法访问纯文本文档,但仍在其他浏览器上运行。

函数基本上是这样运行的:

<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();
});

示例在这里: https://www.channelfireball.com/articles/the-return-of-nationals/

只需找到“Temur Black”套牌列表,然后点击图片示例上方的图标:Deckilst icon

我似乎无法弄清楚是什么导致它在 Chrome 中打开一个空白窗口,而它曾经可以正常工作,这可能是 SSL 的问题吗?

谢谢

【问题讨论】:

    标签: javascript google-chrome window.open


    【解决方案1】:

    Chromium 团队intentionally deprecated and removed the ability to open data URLs。自 Chrome 61 起,此更改似乎已生效。

    【讨论】:

    • 好吧,那很有帮助,我想我唯一的解决方案是不使用它们。谢谢。
    【解决方案2】:

    我最终使用 Ahmed 的方法让它工作,但我必须解码 URI 并将中断替换为 &lt;br&gt;,我认为它会正常工作。

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

    但是,如果有人有其他答案可以使用文本保留它,请告诉我。

    【讨论】:

      【解决方案3】:

      它不适用于 chrome,但您可以使用替代解决方案,例如:

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

      它适用于所有主流浏览器。

      【讨论】:

      • 那种帮助,但我需要将其保存在 .txt 文件中以便快速下载。
      猜你喜欢
      • 2023-04-07
      • 1970-01-01
      • 2019-02-10
      • 1970-01-01
      • 1970-01-01
      • 2020-05-03
      • 2016-01-10
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多