How To Get Site Collection Url Using Javascript?
I am stuck up in a requirement where i need to get the site collection url to pass in a function. Please help?
Solution 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
Solution 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:
<scripttype="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.
Post a Comment for "How To Get Site Collection Url Using Javascript?"