The
Location.reload()
method reloads the current resource, like the Refresh button.This method has an optional
Boolean
parameter, which is false
by default. If true
, the page is always reloaded from the server, ignoring the browser cache.Force page scroll position to top at page refresh in HTML. What I can think of is of some JS or jQuery run as onLoad function of the page to SET the pages scroll to top. A better option would be if there is some property or something to have the page loaded with its scroll position as default (i.e. At the top) which. On my site here when I refresh the page after. Of the content, the refreshed page will open at the link I was at last.
The
forcedReload
flag changes how some browsers handle the user's scroll position. Usually reload()
restores the scroll position afterward, but forced mode can scroll back to the top of the page, as if window.scrollY 0
.The reload may be blocked and a
SECURITY_ERROR
DOMException
thrown. This happens if the origin of the script calling Location.reload()
differs from the origin of the page that owns the Location
object. See Same-origin policy for more information.Syntax
Parameters
forcedReload
Optional- A
Boolean
to indicate that the page will always reload from the server. Iffalse
or unspecified, the browser may reload the page from its HTTP cache.
Example
Specifications
Specification | Status | Comment |
---|---|---|
HTML Living Standard The definition of 'Location.reload()' in that specification. | Living Standard | No change from HTML5. |
HTML5 The definition of 'Location.reload()' in that specification. | Recommendation | Initial definition. |
Browser compatibility
The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request.
Update compatibility data on GitHubDesktop | Mobile | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | Android webview | Chrome for Android | Edge Mobile | Firefox for Android | Opera for Android | Safari on iOS | Samsung Internet | |
reload | ChromeFull support Yes | EdgeFull support 12
| FirefoxFull support Yes | IEFull support Yes
| OperaFull support Yes | SafariFull support Yes | WebView AndroidFull support Yes | Chrome AndroidFull support Yes | Edge MobileFull support Yes | Firefox AndroidFull support Yes | Opera AndroidFull support Yes | Safari iOSFull support Yes | Samsung Internet AndroidFull support Yes |
Legend
- Full support
- Full support
- See implementation notes.
- See implementation notes.
See also
- The
Location
interface it belongs to. - Similar methods:
Location.assign()
andLocation.replace()
.
Join GitHub today
GitHub is home to over 36 million developers working together to host and review code, manage projects, and build software together.
Sign upHave a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
commented Jul 20, 2015
What steps will reproduce the problem:
|
commented Jul 20, 2015
@jericbryledy cause layout is generated by javascript, I don't like it too |
commented Jul 20, 2015
@kybarg The reason is not really the JavaScript but the fact that we enclosing the content into a scrolling <div> .@jericbryledy I don’t think we can do anything about this. It’s the browsers job really to remember scroll positions while reloading (which Chrome does just fine). You’d have to file an upstream bug against your respective browser. |
commented Jul 20, 2015
Oh I see. Just FYI, I have tried http://www.getmdl.io/ on Chrome and Firefox for both Windows and Linux, + Internet Explorer which none remembers the scroll. |
commented Jul 20, 2015
@surma Testing here on the latest dev channel of Chrome it isn't going back to the previous scroll position either. Looks like this is a side-effect of how layout is handled. |
commented Jul 20, 2015
Removing position:absolute from .mdl-layout__container seems to fix this. https://github.com/google/material-design-lite/blob/master/src/layout/_layout.scss#L58 |
commented Jul 21, 2015
will this give side effects though? |
commented Jul 21, 2015
I think it does. The line was added to fix a layout issue but the commit does not reference a GitHub issuse. Commit: d8e63d6 |
commented Jul 21, 2015
how do you reopen an issue? |
commented Jul 21, 2015
You can't re-open your own issue on github if a collaborator has closed it. You'd need to file a new one, perhaps, referencing the old one and giving some reasons why it shouldn't just get closed again as being a duplicate. Good luck. |
commented Jul 21, 2015
Please do not file new issues simply because you feel one was closed improperly. We read follow-up comments and will reopen if appropriate. Nothing can be done here without a layout refactor in a major version since any change could break things already relied upon. |
commented Jul 22, 2015
@Garbee@addyosmani I was thinking about reopening this and marking it as v2 or something. A refactor of the entire layout component might be desirable and feasible. WDYT? |
commented Jul 22, 2015
I think we have enough little problems with Layout cropping up. Instead of re-opening we should make a new issue to track the layout issues brought up that need a BC break. Tag it right and use it for tracking reference. |
commented Jul 22, 2015
SGTM |
referenced this issue Aug 12, 2015
ClosedLayouts lose content scroll position on browser back button #1378
referenced this issue Oct 13, 2015
ClosedScroll position not 'remembered' when you go back #1740
commented Oct 13, 2015
In my view this a very serious problem and so user-unfriendly that I cannot use the framework for any real stuff. |
commented Oct 13, 2015
We know it is a real problem. However, we are doing our best to not break things within a major version. So there is nothing we can do here until 2.x when a full layout refactor is being carried out. |
commented Oct 14, 2015
Fair enough. As a workaround the scroll position can be stored when a page is unloaded and restored when the page is loaded again (see https://developer.mozilla.org/en-US/docs/Web/API/History_API) A lot of the stuff I work with uses history.state anyway... It would be very informative if the examples/templates included examples of 'single page' applications. The examples would illustrate the best/correct way to structure multiple pages in the DOM, how to transition between pages and how to 'remember' the scroll position on the different pages. |
commented Jan 5, 2016
For those who lost faith) Now scroll position is remembered! |
referenced this issue Mar 24, 2016
OpenPage refresh causes page to scroll to the top #4140
referenced this issue Aug 16, 2016
OpenInfinite scroll - when on paged home page, allow IS to load previous posts when scrolling up. #4688
referenced this issue Sep 8, 2016
ClosedDirect hash URL does not scroll automatically to the ID #4726
commented Oct 8, 2016
This worked for me : Add this code in css file AFTER importing material.min.css .mdl-layout__container { position: relative; } |
commented Jan 29, 2017
@pratik the header wouldn't follow you as you scroll down the page if you do that |
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment