in Web and Tech

I learned today that…

… the variables passed on to a URL (e.g. x and y in http://infragrey.com?x=1&y=2) may be accessed in javascript using the following property “search” of the object “Location”. Neat.

Going further, there appears to be a host of other useful properties and methods for this object: host, hostname, href, pathname, port, protocol, etc.

As a PHP developer I never looked much into the HTML DOM (Document Object Model). The equivalent of the “search” property in PHP is exposed via $_GET.

… the property responseText as returned by either XMLHttpRequest or XMLHTTP ActiveX object, which returns full text. There is the property responseXML which returns a full parsable XML. Neat.

Update: (13 June 2014)
Here’s a cool function I ran into:


function GetUrlValue(VarSearch){
var SearchString = window.location.search.substring(1);
var VariableArray = SearchString.split('&');

for(var i = 0; i < VariableArray.length; i++){
var KeyValuePair = VariableArray[i].split('=');
if(KeyValuePair[0] == VarSearch){
return KeyValuePair[1];
}
}
}

Echoed from:
http://javascriptproductivity.blogspot.com/2013/02/get-url-variables-with-javascript.html

Write a Comment

Comment