I am stuck up in a requirement where i need to get the site collection url to pass in a function. Please help?
-
2What is a "site collection url"?Armin– Armin2012-01-17 13:09:27 +00:00Commented Jan 17, 2012 at 13:09
-
2@Armin -- google it. Vinod -- you need to explain where you're having a problem.maxedison– maxedison2012-01-17 13:14:35 +00:00Commented Jan 17, 2012 at 13:14
-
Are you kidding? It is not me, who has a question about it! But maybe I should open a question on stackoverflow ;-)Armin– Armin2012-01-17 13:17:05 +00:00Commented Jan 17, 2012 at 13:17
-
9Armin, this is SharePoint specific (and, if you work in that field, it is a very common term). Since the post was tagged with "SharePoint", there is no need to explain it in the question.naivists– naivists2012-01-17 13:19:14 +00:00Commented Jan 17, 2012 at 13:19
Add a comment
|
2 Answers
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
1 Comment
Markus
Important to note that L_Menu_BaseUrl provides only a relative location of the current site / subsite you are in. It does not necessarily reflect the site collection URL.
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.
3 Comments
Bogdan M.
or SP.ClientContext.get_current().get_url()
Christophe
+1 thanks, I didn't know you could just include controls in script blocks
Jussi Palo
Code block are rarely allowed, so alternative 2 usually doesn't work.