gpt4 book ai didi

javascript - Angular 5 : Get host name and app name from URL

转载 作者:太空狗 更新时间:2023-10-29 18:12:44 25 4
gpt4 key购买 nike

我当前的网址是:

https://localhost:8080/MyApp/manager/dashboard

在上面的 url 中,我只想获取 https://localhost:8080/MyApp/部分。

有什么方法可以在不硬编码的情况下获取它吗?

最佳答案

window.location 包含很多信息。假设网址是 https://example.com:80/a/b/c ,您可以在 Angular 中轻松获取以下信息:

window.location.hostname = "example.com"
window.location.host = "example.com:80"
window.location.protocol = "https:"
window.location.port = "80"
window.location.pathname = "/a/b/c"
window.location.href = "https://example.com:80/a/b/c"

关于javascript - Angular 5 : Get host name and app name from URL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49297680/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com