admin管理员组文章数量:1426072
I'm using window.open in a function to open a web page, which displays help for the current page.
The pages URL are stored in DB , some pages need authentication.
For these pages, the first time we call them the user has to authenticate, but if he closes the page and opens it another time , it's the cached page that is displayed.
I've try to add the time to the url, in order to not display the cached page
var oDate = new Date();
window.open(url+oDate.getTime());
But the browser is still displaying the cached url.
Any idea to resolve this problem?
Thanks.
I'm using window.open in a function to open a web page, which displays help for the current page.
The pages URL are stored in DB , some pages need authentication.
For these pages, the first time we call them the user has to authenticate, but if he closes the page and opens it another time , it's the cached page that is displayed.
I've try to add the time to the url, in order to not display the cached page
var oDate = new Date();
window.open(url+oDate.getTime());
But the browser is still displaying the cached url.
Any idea to resolve this problem?
Thanks.
Share Improve this question edited Sep 2, 2010 at 12:45 Stephen 6,0974 gold badges39 silver badges55 bronze badges asked Sep 2, 2010 at 12:41 MouadhMouadh 2991 gold badge4 silver badges12 bronze badges 2-
3
It really should be
window.open(url + '?x=' + new Date().getTime())
, unless there are other parameters; the point is that it's going to break the URL to just stick the date on the end like that. – Pointy Commented Sep 2, 2010 at 12:49 - that's what i'm doing actually, It's a missing – Mouadh Commented Sep 2, 2010 at 14:53
3 Answers
Reset to default 2You may want to try explicitly adding meta tags to your page:
<!-- HTTP 1.1 -->
<meta http-equiv="Cache-Control" content="no-store"/>
<!-- HTTP 1.0 -->
<meta http-equiv="Pragma" content="no-cache"/>
<!-- Prevents caching at the Proxy Server -->
<meta http-equiv="Expires" content="0"/>
Set clearcache or clearsessioncache equal to yes as required:
window.open(url, '_blank', 'location=yes', 'clearcache=yes');
Try this, if you want to open a new page, without caching problems... it seems to work for me:
function openGoogleLinkWithDummy()
{
var randNumber = Math.floor(Math.random()*99);
var str="How are you doing today? " + randNumber;
window.open("http://www.google.?q=cat&" + randNumber);
}
It surely works if you want to load a external javascript file (from server side code, at example, you append a random number to the name of the zzz.js file and it seems like zzz.js?v=123) but the trick will be ok for your problem, too.
The browser sees a different "version" every time you click the link because of the dummy number appended to the end.
Bye!
本文标签: javascriptwindowopen cache problemStack Overflow
版权声明:本文标题:javascript - window.open cache problem - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745391318a2656608.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论