/** * @copyFrom http://Finn-Rasmussen.com/myphp-1.11/myphp-1.11-js/html/javascript/Request.js.php * Copyrigt notice: You may copy the source code as is as long as you keep the copy right notice intact * * @package javascript * @author http://Finn-Rasmussen.com * @copyright http://Finn-Rasmussen.com * @version 1.11 * @since 27-nov-2009 */ var Request = new function() { // proporties this.key = new Array(); this.value = new Array(); this.getKey = function(index) { return this.key[index]; } this.setKey = function(index,key) { this.key[index] = key; } this.getValue = function(index) { return this.value[index]; } this.setValue = function(index,value) { this.value[index] = value; } this.getSize = function() { if (this.key.length!==this.value.length) { alert("Error in Request.js, function getSize(), differences found in the length\r\nlength of this.key.length="+this.key.length+"\r\nlength of this.value.length="+this.value.length); } return this.key.length; } this.getParameter = function(key) { var value = ''; var size = this.getSize(); for (var i = 0; i < size; i++) { if (key === this.getKey(i)) { // Found a match value = this.getValue(i); } } return value; } this.init = function() { var url = '' + document.location.href; var query = url.split('?'); if (query[1]) { // Any query string? var pairs = query[1].split('&'); // Get all key/value pairs x=a&y=b&z=c ... for(var i = 0; i < pairs.length; i++) { var keyValue = pairs[i].split('='); // Find key/value pair x=a if (keyValue[1]) { this.setKey (i,keyValue[0]); // Create request elements this.setValue(i,keyValue[1]); } else { // value = '', So skip this } } } else { // No request parameters found } } this.init(); }