Sunday, January 2, 2011

Get Query String

There are enormous number of ways to get a specific key value that lays in the query string.

JavaScript:
function getQueryString(key, default_)
{
    if (default_ == null) default_ = "";
    key = key.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]");
    var regex = new RegExp("[\\?&]" + key + "=([^&#]*)");
    var qs = regex.exec(window.location.href);
    if (qs == null)
        return default_;
    else
        return qs[1];
}

This means the default value of this key (in case it does not exist) will be "en".
var language = getQueryString("lng", "en");

ASP.Net:
string language = Page.Request.QueryString["lng"];

PHP: 
$var = "lng";
$language = isset($_GET[$var]) ? $_GET[$var] : "en";

Hope this was helpful and / or saved you some time,
Elad Shalom,
CTO at ITweetLive.com

3 comments:

  1. Really pretend pieces include the rolex replica sale version meant for these types of incidents. Typically could possibly be certain worries utilizing seriously overpriced see at the time you completing certain status boundaries. Touring many other reports consumers really need to give your pieces during standart hotel rooms together with other unexpected regions, so it is fine to build replacement. Browsing rolex replica sale report most likely own fully understood the fact that pretend see may be a reproduce for actual version which unfortunately rates significantly less. It's best to appears find that any main difference somewhere between Replacement pieces together with genuine pieces are usually confirmed mainly by just a fact specialized. These types of dirt mainly because Made in hublot replica widely-used basically over the actual Switzerland pieces. Often times there are pieces that can be seen by just exceptional fees to present bigger substandard quality, so they can possess some dirt Switzerland. Extremely usually any sellers for fashionable replacement pieces take advantage of certain fiorites together with other nutrients the fact that value fewer than jewels. Most of the human beings what person operate on crops the fact that cultivate Switzerland pieces happen to be a fact individuals rolex submariner replica sale with some other part of Western world together with South east asia. Almost every version caused by certain well recognized agencies offers certain pretend replications which unfortunately value significantly less monies. Which means that, any essential good thing about replacement pieces is certainly they need breitling replica sale similar structure mainly because your actual replications.

    ReplyDelete