How to get site collection url using javascript? [closed]

送分小仙女□ 提交于 2019-12-11 08:18:51

问题


I am stuck up in a requirement where i need to get the site collection url to pass in a function. Please help?


回答1:


You can use the L_Menu_BaseUrl variable, it is set automatically by some of SharePoint's default scripts.

You can find more information about it here

  • http://vrdmn.blogspot.com/2011/08/javascript-lmenubaseurl-varaible-for.html
  • http://weblogs.asp.net/jan/archive/2009/05/18/determine-the-url-of-sharepoint-web-services-using-jquery-javascript.aspx



回答2:


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:

<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.

I hope you got the idea. Good luck.



来源:https://stackoverflow.com/questions/8895105/how-to-get-site-collection-url-using-javascript

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!