如何在单击后退按钮时从代码中注入Javascript? (asp.net)

时间:2021-07-05 04:05:31

How to inject JS code when browser's button is clicked? I noticed that RegisterStartupScript during that page life cycle doesn't inject any JS code.

单击浏览器按钮时如何注入JS代码?我注意到该页面生命周期中的RegisterStartupScript没有注入任何JS代码。

OR

要么

How to force any browser to not use the cache and do a fresh complete page load when back button is used?

如何强制任何浏览器不使用缓存并在使用后退按钮时执行新的完整页面加载?

4 个解决方案

#1


0  

you can check the Referring URL (through Request object or HTTP Server Variables) to see if it comes from the certain page in the Page Load event and then load your javascript from there.

您可以检查引用URL(通过请求对象或HTTP服务器变量)以查看它是否来自页面加载事件中的特定页面,然后从那里加载您的JavaScript。

#2


0  

I think that depends on what you have that is being cached... for example, in a project I had IE caching images, and no matter if you pressed the back button or refresh the page, the image won't be refreshed. So the solution was to add a querystring to the img source with a timestamp.

我认为这取决于您所拥有的缓存内容...例如,在项目中我有IE缓存图像,无论您是按下后退按钮还是刷新页面,图像都不会刷新。因此解决方案是使用时间戳向img源添加查询字符串。

Hope it helps.

希望能帮助到你。

#3


0  

Try adding the following line to the Page Load event. The page will not be cached and will be reloaded, not retreived from the cache.

尝试将以下行添加到Page Load事件。该页面不会被缓存,将被重新加载,而不是从缓存中检索。

Response.Cache.SetCacheability(HttpCacheability.NoCache);

#4


0  

I think you want to set the HttpCachePolicy as follows:

我想你想要设置HttpCachePolicy如下:

Response.Cache.SetCacheability(HttpCacheability.NoCache);

#1


0  

you can check the Referring URL (through Request object or HTTP Server Variables) to see if it comes from the certain page in the Page Load event and then load your javascript from there.

您可以检查引用URL(通过请求对象或HTTP服务器变量)以查看它是否来自页面加载事件中的特定页面,然后从那里加载您的JavaScript。

#2


0  

I think that depends on what you have that is being cached... for example, in a project I had IE caching images, and no matter if you pressed the back button or refresh the page, the image won't be refreshed. So the solution was to add a querystring to the img source with a timestamp.

我认为这取决于您所拥有的缓存内容...例如,在项目中我有IE缓存图像,无论您是按下后退按钮还是刷新页面,图像都不会刷新。因此解决方案是使用时间戳向img源添加查询字符串。

Hope it helps.

希望能帮助到你。

#3


0  

Try adding the following line to the Page Load event. The page will not be cached and will be reloaded, not retreived from the cache.

尝试将以下行添加到Page Load事件。该页面不会被缓存,将被重新加载,而不是从缓存中检索。

Response.Cache.SetCacheability(HttpCacheability.NoCache);

#4


0  

I think you want to set the HttpCachePolicy as follows:

我想你想要设置HttpCachePolicy如下:

Response.Cache.SetCacheability(HttpCacheability.NoCache);