1

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

4
  • 2
    What is a "site collection url"? Commented Jan 17, 2012 at 13:09
  • 2
    @Armin -- google it. Vinod -- you need to explain where you're having a problem. Commented 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 ;-) Commented Jan 17, 2012 at 13:17
  • 9
    Armin, 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. Commented Jan 17, 2012 at 13:19

2 Answers 2

6

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

Sign up to request clarification or add additional context in comments.

1 Comment

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

3 Comments

or SP.ClientContext.get_current().get_url()
+1 thanks, I didn't know you could just include controls in script blocks
Code block are rarely allowed, so alternative 2 usually doesn't work.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.