0

in our project we ha multiple pages in . i want to show the particular view name on my layout view. for example my path is http://localhost:64632/admin/index.html#/Subscribe. then the "subscribe" name should shou on main view. i want this code using javascript. asp.net C# javascript, webapi

kumar
  • 31
  • 7

1 Answers1

2

You can get the current url by using javascript:

var x = window.location.href; 

If you want the string after the '#/' you could use the following

var x = window.location.href.split('#/')[1];
pascalzon
  • 116
  • 1
  • 9
  • Hi thank you for your response. its working fine, but the value of x is loading when the page refresh only. this is my index view
  • {{pagetitle}}
  • – kumar May 23 '18 at 08:58
  • my js is var page = window.location.href.split('#/')[1]; $scope.pagetitle = page; – kumar May 23 '18 at 09:00
  • it should change the title name when i click the menu. but its not changing. when i refresh the entire page then only its changing the page title as per i want. what should i do? please help me. – kumar May 23 '18 at 09:06
  • Instead "window.location.href" use "$location.absUrl()". You need to inject '$location' just like '$scope' – vijayliebe May 23 '18 at 09:53
  • This is also working same as previous. index.js is not reloading. without reloading i need to get the changed path. – kumar May 23 '18 at 10:03
  • well it all depends on the framework you are using but since you have interpolation i guess you are using angular(JS)?. The example of @vijayliebe is correct in AngularJS but you would still have to subscribe to the page change event otherwise your code doesn't run again (e.g. like this: https://stackoverflow.com/questions/14765719/how-to-watch-for-a-route-change-in-angularjs) – pascalzon May 26 '18 at 09:39