而不是使用背景页面modify历史导航行为,通过首先不创建历史条目来避免该问题。
例如,通过使用location.replace http://www.whatwg.org/specs/web-apps/current-work/multipage/history.html#dom-location-replace in a 内容脚本 https://developer.chrome.com/extensions/content_scripts.html:
// Running on http://domain.com/page2.html
location.replace('http://domain.com/page2.html&aaa');
清单文件:
"content_scripts": [{
"matches": ["*://domain.com/page2.html"],
"js": ["redirect.js"],
"run_at": "document_start",
"all_frames": true
}],
EDIT:
你声称location.replace
不从服务器获取资源。这不是真的。您遇到的情况是您的页面是cached http://en.wikipedia.org/wiki/Cache_%28computing%29#Web_cache通过浏览器。要确保从服务器重新加载页面,请使用缓存清除 http://www.adopsinsider.com/ad-ops-basics/what-is-a-cache-buster-and-how-does-it-work/方法,例如将随机查询字符串参数附加到您的 URL:
// Running on http://domain.com/page2.html
location.replace('http://domain.com/page2.html?aaa&_t=' + new Date().getTime());
在前一种情况下,您将导航到http://domain.com/page2.html?aaa&_t=1234...
。的价值1234...
相当独特,因此该页面永远不会获取浏览器的本地缓存。
你控制服务器吗?如果是,您还可以通过标头禁用缓存。有关此主题的更多信息,请参阅确保所有浏览器中的网页都不会被缓存 https://stackoverflow.com/questions/49547/making-sure-a-web-page-is-not-cached-across-all-browsers.