JohnSmith
JohnSmith

Reputation: 437

Get URL to JS file

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

Upvotes: 1

Views: 1441

Answers (3)

Ilya Klementiev
Ilya Klementiev

Reputation: 593

Also you can use:

alert(document.URL);

Get current URL in web browser

Upvotes: 0

CodingIntrigue
CodingIntrigue

Reputation: 78535

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);

Upvotes: 1

PLPeeters
PLPeeters

Reputation: 1040

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.

Upvotes: 0

Related Questions