Important notice

Please note that this blog is discontinued here. All the posts are also coppied to my new blog at http://boris.gomiunik.net.
Important: Due to large amount of comment spam further commenting has been disabled here. If you wish to send me a comment, plase look up the same post on my new blog and leave comment there. Thanks!

7/24/2008

Couple of useful JavaScript global variables in SharePoint

If you're using custom JavaScripts with SharePoint some global JavaScript variables may come in handy.

These variables work if you're using SharePoint's default or any other custom master page.

L_Menu_BaseUrl - the base URL of the site / subsite. Very useful when you need to determine the absolute path of the site in JavaScript. Example: document.location = L_Menu_BaseUrl + 'lists/calendar/allitems.aspx' //redirects to Calendar list

L_Menu_LCID - the LCID of the site you're in. Useful if you need to determine the language of the site. The list of Locale IDs can be found here. I'm using the LCID for localizations in ERTE project. See the example of checking LCID below:

.
L_Menu_SiteTheme - the name of the theme applied to the site.

There is one more useful variable, but this one can't be used on custom master pages that you created. This one is used in the SharePoint's default pages:

_spUserId - the ID of the logged in user.

Oznake ponudnika Technorati: ,

5 comments:

Rich Finn said...

sweet!! great info for the ajax moss devs...

chris said...

Hi,
Is it possible to see a list of these global variables?
For instance, I would like one to retrieve the current url not just the base?

Thanks alot

Chris

Boris Gomiunik said...

Hi, Chris. For this you don't need the SharePoint's variables. You can use the JavaScript DOM. If you need the full url you can use document.location or document.location href (for example: alert(document.location.href).

For other options concerning URL you can find some more useful information here:

http://www.exforsys.com/tutorials/javascript/javascript-location-object-properties.html

Emanuel said...

Great! After googling for five hours you have finally discovered me option how to get current site's URL.

Thank you.

ScytaleUK said...

"L_Menu_LCID - the LCID of the site you're in."

Incorrect. This is the site setting not the display setting. If the user does not follow the site's regional settings and has chosen their own, then this variable will be incorrect