简体   繁体   English

在 window.open() 时删除“about:blank”

[英]remove "about:blank" when window.open()

I have a function that will dynamicaly window.open() to a specific resource.我有一个 function,它将动态地window.open()到特定资源。 I would like to remove the "about:blank" that appears while the page load and display a loading message.我想删除页面加载时出现的“about:blank”并显示加载消息。

Is it possible?可能吗?

Here is my function:这是我的 function:

const windowReference = window.open();

    try {
        AppProductAuthenticationApi.getUrlAccess(apuaId, query).then((res: {urlAccess: string} | undefined | null) => {
            if (res && res.urlAccess) {
                windowReference &&
                    (windowReference.location = `${res.urlAccess}${
                        null !== queryString && typeof queryString !== "undefined" ? queryString : ""
                    }`);
            } else {
                windowReference && windowReference.close();
            }
        });
    }

Yes, it is possible to remove the "about:blank" page and display a loading message while the page is loading.是的,可以删除“about:blank”页面并在页面加载时显示加载消息。 Here is one way you could do this:这是您可以执行此操作的一种方法:

Add an event listener to the load event of the new window.给新的window的load事件添加一个事件监听器。

windowReference.addEventListener('load', () => { Do something when the page has finished loading });

Inside the event listener function, you can use the windowReference.document property to access the document object of the new window:在事件监听器 function 内部,可以使用 windowReference.document 属性访问新的 window 的文档 object:

    windowReference.addEventListener('load', () => {
 windowReference.document.body.innerHTML = '';
windowReference.document.body.innerHTML = '<h1>Loading...</h1>';
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM