Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/29.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在javascript中获取页面的完整路径_Javascript_Asp.net - Fatal编程技术网

如何在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改为指向和。