Is there any way to force reload a page with a JavaScript query?
The title might be a bit mis开发者_JS百科leading, but I don't know how else to explain it.
Basically I'm at this URL:
www.mysite.com/shop/6-dresses#filter=[manufacturer:4]
And I want to make a link that would change it to
www.mysite.com/shop/6-dresses#filter=[manufacturer:5]
(e.g. like <a href="www.mysite.com/shop/6-dresses#filter=[manufacturer:5]"></a>
)
But it doesn't seem to load unless I click on it and refresh the page after.
Is there anyway I can alter the link code so that it forces to reload the page fully?
You'll have all you need here : https://developer.mozilla.org/en/window.location#Methods
have you tried window.location = "www.mysite.com/shop/6-dresses#filter=[manufacturer:5]"
The only difference between both links is the fragment identifier. That's why the page isn't reloading. The reason for this is RFC 3986 - Uniform Resource Identifier (URI): Generic Syntax (emphasis mine):
When a URI reference refers to a URI that is, aside from its fragment component (if any), identical to the base URI (Section 5.1), that reference is called a "same-document" reference.
[...]
When a same-document reference is dereferenced for a retrieval action, the target of that reference is defined to be within the same entity (representation, document, or message) as the reference; therefore, a dereference should not result in a new retrieval action.
You're fighting against the browser's correct behavior, and implicitly going against the user's expectations. I suggest you change the URLs to something like this:
www.mysite.com/shop/6-dresses?filter=[manufacturer:5]#filter=[manufacturer:5]
This will result in a reload of the page, without being dependent on JavaScript. Stack Overflow uses a similar approach for linking to answers:
stackoverflow.com/questions/3483627/some-question/3483650#3483650
精彩评论