3

I have a current URL:

http://www.test.com/p1234?utm_source=....

How do I get a URL with the format http://www.test.php/p1234

I am using javascript document.URL, the result is http://www.test.com/p1234?utm_source=....

Domecraft
  • 1,645
  • 15
  • 26
linh.gust
  • 51
  • 1
  • 5

2 Answers2

2

This is the correct answer:

window.location.host + window.location.pathname;
ebertx
  • 21
  • 2
  • 1
    also prefix the protocol used. window.location.protocal + "//" window.location.host + window.location.pathname; – Rahul Malu Jun 27 '16 at 07:26
0

You want this:

var location = window.location.host + window.location.pathname;

see the docs: https://developer.mozilla.org/en-US/docs/Web/API/Location

mkoryak
  • 57,086
  • 61
  • 201
  • 257