Chrome应用程序如何重新加载? (document.location.reload是不允许的) [英] How can chrome app reload itself? (document.location.reload is not allowed)

查看:200
本文介绍了Chrome应用程序如何重新加载? (document.location.reload是不允许的)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发Chrome应用程序。我需要经常刷新它,但不能通过调用:

I am developing chrome app. I need to refresh it often but it is not possible by calling:

window.location.reload()

document.location.reload()

在控制台中有错误消息:

In console there is error message:


无法打开同窗链接到
chrome-extension://dmjpjfnceeilhihfbkclnbnhjpcgcdpn/window.html;尝试使用
target =_ blank。

Can't open same-window link to "chrome-extension://dmjpjfnceeilhihfbkclnbnhjpcgcdpn/window.html"; try target="_blank".


推荐答案

p>

Instead use this:

chrome.runtime.reload();

如果您打开了开发者工具,它们也会被刷新。此外,如果您只打开了应用程序窗口和开发人员工具(并且您关闭了浏览器本身),它似乎会关闭应用程序,但不会再次加载它,因此您必须保持浏览器处于打开状态(例如最小化)。

If you have developer tools opened, they will be refreshed as well. Also it seems that if you have only opened app window and developer tools (and you closed browser itself), this will close app but will not load it back again, so you have to keep browser open (e.g. minimized).

在开发期间,您可以添加回调F5键来刷新应用程序:

During development you can add callback for F5 key to refresh the app:

window.addEventListener('keydown', function () {
    if (event.keyIdentifier === 'F5') {
        chrome.runtime.reload();
    }
});  

这篇关于Chrome应用程序如何重新加载? (document.location.reload是不允许的)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆