0

HOw do i get this base path?

http://localhost:1313/

my code right now is

 var getUrl = window.location;
  var baseUrl = getUrl .protocol + "//" + getUrl.host + "/" + getUrl.pathname.split('/')[1];

which gives me

http://localhost:1313/manual

i need to remove "manual"

  • Duplicate Question - You can find an answer at the following question: https://stackoverflow.com/questions/1368264/how-to-extract-the-hostname-portion-of-a-url-in-javascript/17336519#17336519 – YoungChoi Aug 17 '21 at 18:21

2 Answers2

0

This should do the trick

var baseUrl = window.location.origin;
Daniel
  • 61
  • 5
0

Please use this code.

var getUrl = window.location.origin;
Kirill Savik
  • 1,228
  • 4
  • 7