Reload page with anchor using Javascript or Jquery -


i using anchors in url kind of variable javascript, eg:

mysite.com/itempage.html#item75 

this works when click link on other page, not on actual page in question (itempage.html).

instead of reloading page, clicking link changes url. since page not reload, none of javascript runs again.

does know way reload page new url?

so far have tried:

html

<div id="itemmenu">   <a id="item75" href="#">item 75</a>   <a id="item11" href="#">item 11</a> </div> 

jquery

$( "#itemmenu a" ).each(function(index) {      $(this).on("click", function(){         var linkid = $(this).attr('id');          var winloc = "mysite.com/itempage#" + linkid;         window.location  = winloc;     }); }); 

this indeed expected behavior: not reloading page, , scrolling page anchor. also, "#..." part purely happening on client-side, , browsers don't send part of uri server, so:

are considered same uris server.

if need reload page, may as:

<div id="itemmenu">   <a id="item75" href="?item=75">item 75</a>   <a id="item11" href="?item=11">item 11</a> </div> 

if don't need reload page, rerun javascript, associate required javascript functions click event on of concerned links.


additional notes:

  1. $(this).on("click", ...) can shortened $(this).click(...).

  2. you don't need actual javascript code: set hrefs directly in html code instead of changing them through javascript.


Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

ios - Change Storyboard View using Seague -