如何在javascript中获取页面的完整路径
我知道如何在javascript中获取页面的完整路径,javascript,asp.net,Javascript,Asp.net,我知道var pathname=window.location.pathname仅返回路径,并且var url=window.location.href返回完整的URL 现在假设我的站点根目录中有一个页面MyPageName.aspx,并且我的站点可以部署在服务器serverone、servertwo和serverthree上 在Serverone上,我想显示 在服务器2上,我想显示 在serverthree上,我想显示 那么,如何在当前环境中获取页面的完整URL路径,而不必浏览到该页面,但事先
var pathname=window.location.pathname
仅返回路径,并且var url=window.location.href代码>返回完整的URL
现在假设我的站点根目录中有一个页面MyPageName.aspx,并且我的站点可以部署在服务器serverone、servertwo和serverthree上
在Serverone上,我想显示
在服务器2上,我想显示
在serverthree上,我想显示
那么,如何在当前环境中获取页面的完整URL路径,而不必浏览到该页面,但事先知道该页面存在
我想在母版页的某个位置显示URL。您尝试过吗
document.URL
阅读您可以使用window.location.origin
返回.com
之前的所有内容:
var url = window.location.origin;
-> "http://example.com"
由于MyPageName.aspx
看起来是静态的,因此您可以使用字符串连接将其附加到末尾:
url += "/MyPageName.aspx";
-> "http://example.com/MyPageName.aspx"
演示
var url=window.location.origin+“/MyPageName.aspx”;
document.write(url)代码>我已将您问题中的示例URL改为指向和。