window.open cache problem
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 auth开发者_运维问答enticate, 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.
You 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.com?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!
精彩评论