Javascript和Html-返回Html代码中的url地址

Javascript和Html-返回Html代码中的url地址,javascript,html,url,get,Javascript,Html,Url,Get,我正在尝试使用html和javascript获取当前页面的完整url地址。但我并不擅长网络语言,所以我想请你帮忙 以下是我正在尝试的: Your website url is: <script>(window.location.host)</script> 您的网站url是:(window.location.host) 您可以使用的方法(不推荐使用) 您的网站url是:document.write(window.location.host) 更好的方法是在那里放置一

我正在尝试使用html和javascript获取当前页面的完整url地址。但我并不擅长网络语言,所以我想请你帮忙

以下是我正在尝试的:

Your website url is: <script>(window.location.host)</script>
您的网站url是:(window.location.host)

您可以使用的方法(不推荐使用)

您的网站url是:document.write(window.location.host)
更好的方法是在那里放置一个占位符,并用innerHTML/textContent替换内容

Your website url is: <span id="loc"></span>
<script>document.getElementById("loc").textContent = window.location.host;</script>
您的网站url是:
document.getElementById(“loc”).textContent=window.location.host;

非常感谢您,先生!这是我想要的。编辑哈哈。再次感谢您如此快速的响应和解决我的问题!
Your website url is: <span id="loc"></span>
<script>document.getElementById("loc").textContent = window.location.host;</script>