javascript 如何使用javascript获取网站集网址?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/8895105/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to get site collection url using javascript?
提问by Vinod
I am stuck up in a requirement where i need to get the site collection url to pass in a function. Please help?
我遇到了需要获取网站集 url 以传递函数的要求。请帮忙?
回答by naivists
You can use the L_Menu_BaseUrl
variable, it is set automatically by some of SharePoint's default scripts.
您可以使用该L_Menu_BaseUrl
变量,它由某些 SharePoint 的默认脚本自动设置。
You can find more information about it here
您可以在此处找到有关它的更多信息
回答by Maks Matsveyeu
you have 2 options: 1) in your javascript use the L_Menu_BaseUrl variable. it contains the relative url of the site collection 2) if you need the absolute url you can use the following javascript code snippet in the server control:
您有 2 个选项:1) 在您的 javascript 中使用 L_Menu_BaseUrl 变量。它包含网站集的相对 url 2) 如果您需要绝对 url,您可以在服务器控件中使用以下 javascript 代码片段:
<script type="text/javascript">
var siteUrl = "<%= SPContext.Current.Site.Url %>";
</script>
It renders absolute url to the site collection. the approach (2) allows you to form up the url you need on the server side.
它呈现网站集的绝对网址。方法 (2) 允许您在服务器端形成所需的 url。
I hope you got the idea. Good luck.
我希望你有这个想法。祝你好运。