3

In Internet Explorer 10, if you press the back button it would try to fetch the previous page from the browser cache. This behavior differs from virtually every other browser including IE9 in which pressing the back button would do a full reload of the previous page instead of reusing the cache.

How do I communicate with IE10 from the website, possibly using javascript/headers etc to not do this cache utilization for the site globally?

(Note: I'm not looking for an IE10 setting to disable this. I'm looking for a solution that can be implemented in the Website and not the browser to instruct IE10 to not use this cache for the back button). Also I'm looking for a global solution that works for every page in the site...

I use PHP/Jquery for the site

so here's more information

The page is a Form. It contains some dynamically loaded info. (Let's say it contains the number of times the user submitted the form)

You click on the submit button of the form. You will then then get redirected to the form's action page.

Then you press the back button.

In every other browser, it would reload the initial form with the newly updated "number of times the user submitted the form". In IE10 however, this doesn't happen....How do I get this to happen in IE 10.

Here are some example headers:

1. When you first load the form:

Request Header

Key Value
Request GET /path/to/my/page HTTP/1.1
Accept  text/html, application/xhtml+xml, */*
Accept-Language en-US
User-Agent  Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.1; WOW64; Trident/6.0)
Accept-Encoding gzip, deflate
Host    myhost.com
If-Modified-Since   Tue, 10 Sep 2013 23:55:33 GMT
If-None-Match   "1378857333"
DNT 1
Connection  Keep-Alive
Cookie  __utma=104299925.1011127538.1340896287.1364829735.1378764406.12; __utmz=104299925.1340896287.1.1.utmcsr=(direct)|utmccn=(direct)|utmcmd=(none); has_js=1; __utmc=104299925; __qca=P0-1247924781-1340896285157; _mkto_trk=id:601-CPX-764&token:_mch-sadfsadfze.com-1358808312889-73607; __utma=171146939.775168663.1343066079.1375907514.1378762647.41; __utmz=171146939.1343066079.1.1.utmcsr=(direct)|utmccn=(direct)|utmcmd=(none); s_stats_browser_info=%7B%22pluginInfo%22%3A%7B%22pdf%22%3A%5B%22pdf%22%2C%22application/pdf%22%2C%220%22%5D%2C%22quicktime%22%3A%5B%22qt%22%2C%22video/quicktime%22%2C%220%22%5D%2C%22realplayer%22%3A%5B%22realp%22%2C%22audio/x-pn-realaudio-plugin%22%2C%220%22%5D%2C%22wma%22%3A%5B%22wma%22%2C%22application/x-mplayer2%22%2C%220%22%5D%2C%22director%22%3A%5B%22dir%22%2C%22application/x-director%22%2C%220%22%5D%2C%22flash%22%3A%5B%22fla%22%2C%22application/x-shockwave-flash%22%2C%220%22%5D%2C%22java%22%3A%5B%22java%22%2C%22application/x-java-vm%22%2C%221%22%5D%2C%22gears%22%3A%5B%22gears%22%2C%22application/x-googlegears%22%2C%220%22%5D%2C%22silverlight%22%3A%5B%22ag%22%2C%22application/x-silverlight%22%2C%220%22%5D%7D%2C%22res%22%3A%221920x1080%22%7D; _pk_id.2.1644=19232922ec6753dc.1371502517.1.1371502630.1371502517.; SESS569093948b0206b05eb2212616da3db6=1977iogjr841af2s8l4sd1cjd0; XDEBUG_SESSION=12250; has_js=1; __utmc=171146939

Response Header:

> Key   Value Response  HTTP/1.1 200 OK Date    Tue, 10 Sep 2013 23:55:44 GMT
> Server    Apache/2.2.20 (Ubuntu) X-Powered-By PHP/5.4.15-1~tooptee10+1
> Last-Modified Tue, 10 Sep 2013 23:55:44 +0000 Cache-Control   no-cache,
> must-revalidate, post-check=0, pre-check=0 ETag   "1378857344"
> Keep-Alive    timeout=15, max=9987 Connection Keep-Alive
> Content-Type  text/html; charset=utf-8

2. When you hit the back button to go back to that form

Request Header

>     Key   Value
>     Request   GET /path/to/my/page HTTP/1.1
>     Accept    text/html, application/xhtml+xml, */*
>     Accept-Language   en-US
>     User-Agent    Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.1; WOW64; Trident/6.0)
>     Accept-Encoding   gzip, deflate
>     Host  myhost.com

Response Header

> Key   Value Response  HTTP/1.1 304 Not Modified
> X-Powered-By  PHP/5.4.15-1~tooptee10+1 ETag   "1378857344"
> Keep-Alive    timeout=15, max=9987 Content-Type   text/html; charset=utf-8
> Content-Length    117183 Expires  Tue, 10 Sep 2013 22:55:36 GMT
> Last-Modified Tue, 10 Sep 2013 23:55:44 GMT

Notice that it ends up returning a 304. When I tried this in Firefox, it returned 200 instead when you press the back button.

4

2 回答 2

1

我认为您想要的行为是一种打破用户对后退按钮的期望的行为。

用户期望当他们按下返回时,它会将他们返回到他们之前查看的页面,处于离开时的状态。大多数现代浏览器不仅通过缓存页面,而且通过将页面状态(包括 Javascript 上下文)保留在内存中来实现这一点,这样当通过后退按钮返回页面时,它会处于与之前相同的状态,包括任何它们写入表单或他们与之交互的任何 Javascript。

在大多数浏览器中,您可以Cache-Control通过设置诸如no-cache和之类的标题来强制覆盖它no-store。我不知道no-store对于 IE10 是否适用于您的情况,或者 IE10 是否会忽略这一点并且无论如何都会返回页面。如果是这样,我想我真的不会责怪它。这样做是为了用户的兴趣,既要快速又要返回到以前查看时的页面。

我认为我会采取的方法是重新考虑设计,您不必同意我的看法。如果您不打算向他们展示他们回到那里时看到的相同内容,为什么还要要求用户点击“返回” ?如果您想显示更新的表单,为什么不在POST 后重定向回表单,这将被视为新页面加载并尊重您的Cache-Control标题?这就是我要做的,它已经成为某种事实上的标准。

tl;博士这是可能的,但我不确定,你可以做你想做的事no-store,但我会考虑在POST 之后转向重定向,以免依赖后退按钮而不是返回到之前的状态。

于 2013-09-11T00:40:48.587 回答
0

您也许可以在 PHP 中设置一些标头

Cache-Control: private, must-revalidate, max-age=0
Expires: Thu, 01 Jan 1970 00:00:00
于 2013-09-09T21:49:47.250 回答