admin管理员组文章数量:1122846
I want to set the window open new page's title(this page will open. a pdf file in browser), this is how I do it:
export const handleOpenInBrowserDirect = (projectId: string) => {
if (projectId) {
getPreviewUrl(projectId).then((res) => {
if (ResponseHandler.responseSuccess(res)) {
var newWindow = window.open(res.result, "_blank");
setTimeout(() => {
if (newWindow) {
newWindow.document.title = "New title";
}
}, 300);
}
});
}
};
when I open the new page, the title was changed to New title
. But when the new page rendered done. the title changed to preview
. Am I missing something? what should I do to change the new page title that opened by window open in react?
I have also tried to listening the load event:
export const handleOpenInBrowserDirect = (projectId: string) => {
if (projectId) {
getPreviewUrl(projectId).then((res) => {
if (ResponseHandler.responseSuccess(res)) {
var newWindow = window.open(res.result, "_blank");
if (newWindow) {
newWindow.addEventListener("load", () => {
if (newWindow) {
newWindow.document.title = "New title";
}
});
}
}
});
}
};
I also add this code in the application app component like this:
React.useEffect(() => {
window.document.title = 'Some Name';
},[]);
the title will finally replaced by preview
when the pdf download and loaded done. It look like the google chrome shows the document's title. Also tried loop listening:
export const handleOpenInBrowserDirect = (projectId: string) => {
if (projectId) {
getPreviewUrl(projectId).then((res) => {
if (ResponseHandler.responseSuccess(res)) {
var newWindow = window.open(res.result, "_blank");
const loop = setInterval(function () {
if (newWindow) {
if (newWindow.closed) {
clearInterval(loop);
} else {
newWindow.document.title = "winName";
}
} else {
clearInterval(loop);
}
}, 1000);
}
});
}
};
本文标签: javascripthow to change the window open page title in reactStack Overflow
版权声明:本文标题:javascript - how to change the window open page title in react - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736299980a1930651.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论