问题
I am developing chrome app. I need to refresh it often but it is not possible by calling:
window.location.reload()
or
document.location.reload()
In console there is error message:
Can't open same-window link to "chrome-extension://dmjpjfnceeilhihfbkclnbnhjpcgcdpn/window.html"; try target="_blank".
回答1:
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).
During development you can add callback for F5 key to refresh the app:
window.addEventListener('keydown', function () {
if (event.keyIdentifier === 'F5') {
chrome.runtime.reload();
}
});
来源:https://stackoverflow.com/questions/30751939/how-can-chrome-app-reload-itself-document-location-reload-is-not-allowed