Is it possible to set the language attribute of apex:page via javascript? I actually tried this but I'm not getting the expected result. Example:

<apex:page language="<script>getURL(decodeURIComponent(location.href))</script>" applyHtmlTag="false" showHeader="false" docType="html-5.0" cache="false" >

location.href has query string which value is encoded, and the language is part of the encoded string. getURL() is my javascript function to get the value of language.

I tried removing the script tag, but still has no luck:


I understand that this can be achieved via controller, but that is what I'm trying to avoid since there's lot of process when dealing with controller.

Thanks in advance!

  • 1
    You cannot use javascript for this. Javascript is interpreted in the browser, i.e. it "runs" only after the html output has been delivered from server to your browser. Having that in mind, you must notice that your getURL will execute only (so to say) on your computer, it will not tell the server to render the page/component with specific language. What you must do is retrieve language through the controller and bind it to the page.
    – dino ursic
    Commented Dec 20, 2013 at 10:55

1 Answer 1


You can instead use global variables for your requirements


so if your parameter name is lang

you can use

<apex:page language="{!$CurrentPage.parameters.lang}" applyHtmlTag="false" showHeader="false" docType="html-5.0" cache="false" >

Once you access from URL i think the global variable will be automatically decoded.

  • Thank you Mohith. But the thing is, the query string is encoded. So to decode it, i want to use javascript instead of going through controller.
    – user3734
    Commented Dec 20, 2013 at 6:18
  • 1
    @user3734 Page language has to be determined server-side, for example because it decides on field labels, custom labels... JS is not running at that point (imagine how stupid it would look if page starts to render in English, blinks and JS replaces all texts with say French). Decode the lang earlier (when you construct the link, not when you hit the page) or update the question with a sample link, maybe we'll figure something out with with functions from help.salesforce.com/apex/…
    – eyescream
    Commented Dec 20, 2013 at 8:13
  • @eyescream thank you so much for clearing that up, makes a lot of sense. I think I'll just have to go through the controllers then.
    – user3734
    Commented Jan 2, 2014 at 5:05

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .