窗口不允许将*框架导航导航到数据URL

时间:2022-09-04 21:10:18

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

以下代码将在新窗口中打开pdf文件。

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.

更新chrome之后,它似乎停止了工作。 Appranely,chrome删除了*框架到数据URL的导航。

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

我现在该如何解决我的问题?我需要在新窗口中打开此pdf。任何帮助将不胜感激。

UPDATE

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

使用iFrame解决了它。感谢佩德罗给我的想法。

<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>

1 个解决方案

#1


2  

Deprecations and Removals in Chrome 60:

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.

由于他们对非技术浏览器用户不熟悉,我们越来越多地看到数据:用于欺骗和网络钓鱼攻击的方案。为了防止这种情况,我们阻止网页加载数据:顶部框架中的网址。这适用于标签,window.open,window.location和类似机制。数据:方案仍然适用于页面加载的资源。

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

此功能在Chrome 58中已弃用,现已删除。

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

#1


2  

Deprecations and Removals in Chrome 60:

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.

由于他们对非技术浏览器用户不熟悉,我们越来越多地看到数据:用于欺骗和网络钓鱼攻击的方案。为了防止这种情况,我们阻止网页加载数据:顶部框架中的网址。这适用于标签,window.open,window.location和类似机制。数据:方案仍然适用于页面加载的资源。

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

此功能在Chrome 58中已弃用,现已删除。

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