我如何才能在functions.js-file中获得我网站上functions.js文件的完整路径?
示例:我的JS文件位于以下文件夹/wp-content/themes/example/js/functions.js
我想通过jQuery获取完整路径:http://example.com/wp-content/themes/example/js/functions.js
发布于 2013-05-29 20:16:18
window.location.origin将提供URL的域部分。然后你可以追加你的路径。
https://developer.mozilla.org/en-US/docs/Web/API/window.location
例如:
// Prints "http://stackoverflow.com"
console.log(window.location.origin);发布于 2013-05-29 20:16:16
您可以使用document.location.hostname返回您的主机名。例如,如果您在SO上运行它,它的值将是stackoverflow.com。
发布于 2013-05-29 20:22:04
https://stackoverflow.com/questions/16813611
复制相似问题