1

I am new to jQuery & I tried to resolve this on my own without any luck.

I need to change the the Value in the CSS based on a QueryString using jQuery. I tried couple of scripts which didn't work.

URL Example: http:www.xyz.com/Page.aspx?pageID=101&Language=arabic

Based on the language specified in the URL I have to change the CSS value of float:right in class .Image4x4 and verticleBar before page is displayed.

 .Image4x4
    {
        width:670px;
        float:left; /* for arabic keep right */
        height:550px;
        background-color:Orange; 
    }
    .verticleBar
    {
        width:220px;
        float:left; /* for arabic keep right */
        height:550px;
        background-color:Red;
    }

I tried few scripts but it didn't work as planed.

I would appreciate any help on this.

2
  • Is this because Arabic is read right-to-left (RTL)? Commented Jan 1, 2012 at 20:21
  • @Ayman : Yes i have to change the layout as other language is Arabic Commented Jan 2, 2012 at 7:08

2 Answers 2

3
var queryValues = {};

$.each(window.location.href.split('?').pop().split('&'), function (i, v)
{
    var v = v.split('=');
    if(v.length > 1) // prevent v[1] from erroring if no querystring present
      queryValues[ v[0].toLowerCase() ] = v[1].toLowerCase();
});

if ( queryValues.language == 'arabic' )
{
    $('.Image4x4, .verticleBar').css('float', 'right');
}

If you're not sure there'll always be a query string, you should add code to check for that.

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

6 Comments

That's a beautiful solution - +1
You could use window.location.search instead of window.location.href, that way you only parse the query string part of the URL. See developer.mozilla.org/en/DOM/window.location#Properties
@Leo - But I then anyhow have to remove the ? from the beginning of the string...
@Josep Siber: It is a nice Solution. can you also give me a code snippet which will also detect the browser language so that i can also change language based on the browser setting. I will also try to look for the solution & try to resolve on my own.
You should check it server side: $_SERVER["HTTP_ACCEPT_LANGUAGE"];
|
1

I propose a JavaScript-independent solution...

Assuming that you need to do this because Arabic is read right-to-left (RTL), use ASP to create a list of languages that are RTL. Whenever the language set in the URL is in this list, give the <body> tag an "rtl" class?

If so, you can do something like:

.rtl .Image4x4, .rtl .verticleBar
{
    float:left; /* for arabic keep right */
}

This way you will be able to handle any RTL language.

4 Comments

How do you propose to change it based on the query string?
@Ayman. I have nested Div tags it align all the text in the div tags as per RTL or LTR but it does not change the position of the div tags which are on the right side for ENGLISH, that is y i have to change them using jQuery.
@Ayman: I tried it it does not work even if i hard code the <body dir="rtl">. i have defined my CSS as you have mentioned but it doesnt work.
CSS does not interpret dir. I meant class="rtl".

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.