functions.js-file で自分のサイトの functions.js ファイルへのフル パスを取得するにはどうすればよいですか?
例: 私の JS ファイルは次のフォルダーにあります /wp-content/themes/example/js/functions.js
jQuery 経由でフル パスを取得したい: http://example.com/wp-content/themes/example/js/functions.js
functions.js-file で自分のサイトの functions.js ファイルへのフル パスを取得するにはどうすればよいですか?
例: 私の JS ファイルは次のフォルダーにあります /wp-content/themes/example/js/functions.js
jQuery 経由でフル パスを取得したい: http://example.com/wp-content/themes/example/js/functions.js
window.location.origin
URL のドメイン部分を提供します。次に、パスを追加できます。
https://developer.mozilla.org/en-US/docs/Web/API/window.location
例えば:
// Prints "http://stackoverflow.com"
console.log(window.location.origin);
document.location.hostname
ホスト名を返すために使用できます。たとえば、SO で実行する場合、その値はstackoverflow.com
.