1

How am I able to get the full path to the functions.js file on my site in the functions.js-file?

Example: My JS file is in the following folder /wp-content/themes/example/js/functions.js

I want via jQuery pull the full path: http://example.com/wp-content/themes/example/js/functions.js

JohnSmith
  • 417
  • 4
  • 10
  • 21

3 Answers3

1

window.location.origin will provide the domain part of the URL. Then you can append your path.

https://developer.mozilla.org/en-US/docs/Web/API/window.location

For example:

// Prints "http://stackoverflow.com"
console.log(window.location.origin);
CodingIntrigue
  • 75,930
  • 30
  • 170
  • 176
0

You can use document.location.hostname to return your hostname. For example, if you would run it on SO, its value would be stackoverflow.com.

PLPeeters
  • 1,009
  • 12
  • 26
0

Also you can use:

alert(document.URL);

Get current URL in web browser

Community
  • 1
  • 1
Ilya Klementiev
  • 593
  • 8
  • 12