如何在 functions.js 文件中获取我网站上的 functions.js 文件的完整路径?
示例:我的 JS 文件位于以下文件夹 /wp-content/themes/example/js/functions.js
我想通过 jQuery 拉出完整路径: http ://example.com/wp-content/themes/example/js/functions.js
如何在 functions.js 文件中获取我网站上的 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
.