1

I'm on a page, let's say page.php, and I want to reload it. Here is my first code:

$(location).attr("href", "/page.php");

it perfectly works : the page reloads well.

Now, I'd like to go to a specific place into my page, using anchors:

$(location).attr("href", "/page.php#anchor");

When I do this, browser goes directly to the anchor indeed, without reloading the page, wich isn't what I want.

How could I reload the page THEN go to my anchor?

Felix Kling
  • 795,719
  • 175
  • 1,089
  • 1,143
pistou
  • 2,799
  • 5
  • 33
  • 60
  • `location.href` would do the same thing. – Ja͢ck Mar 07 '13 at 16:51
  • 7
    jQuery is primarily for manipulating the DOM, not arbitrary objects. `location` is such an object for which it does not make sense to pass it to jQuery. – Felix Kling Mar 07 '13 at 16:51
  • `location` is not an element. Don't treat it as such. – Brad Mar 07 '13 at 16:52
  • 2
    possible duplicate of [Javascript: How to truly reload a site with an anchor tag?](http://stackoverflow.com/questions/2319004/javascript-how-to-truly-reload-a-site-with-an-anchor-tag) At least, the advice given there should suffice in your case. ) – raina77ow Mar 07 '13 at 16:52
  • 1
    Why are you doing `$(location).attr("href")`? Where did you learn that? – gen_Eric Mar 07 '13 at 16:56
  • 2
    I'm surprised that it's working; jQuery constructor function is really an omnivore. :) – raina77ow Mar 07 '13 at 16:57
  • @raina77ow you were right :) Your post helped me. – pistou Mar 07 '13 at 17:01
  • Wow, this seems like a simple problem to solve at first! I reckon __[this](http://stackoverflow.com/a/2319021/706561)__ is your best bet. – c24w Mar 07 '13 at 17:03

1 Answers1

-1

You can try window.location.reload()

lavrik
  • 1,456
  • 14
  • 25