- From: Gavin Kistner <gavin@refinery.com>
- Date: Mon, 6 Oct 2003 12:12:55 -0600
- To: Alfred Tsang <atsang@ic.sunysb.edu>
- Cc: www-svg@w3.org
On Wed 10 Sep 2003, Alfred Tsang wrote:
> Is it possible to pass a parameter to svg from http GET method?
> for example, http://localhost/somesvg.svg?foo=bar, how can I access
> foo?
Here's some code which, included on your page, will create a new
keyVals object which can be accessed either by index of
(case-sensitive) key name.
if (/\?(.+)/.test(document.URL)){
var keyVals=window.keyVals=RegExp.$1.split('&');
for (var i=0,len=keyVals.length;i<len;i++){
var pair=keyVals[i].split('=');
keyVals[i]=keyVals[pair[0]]=unescape(pair[1]);
}
} else window.keyVals={};
//For example, with:
//mySVG.svg?foo=bar&jimmy=jammy&objID=11
alert(keyVals[0]); // 'bar'
alert(keyVals.jimmy); // 'jammy'
alert(keyVals.objID+1); // '111'
Note that with the last, all values coming from the querystring are
type string; to use them as numbers, you need to make them such, like:
alert(keyVals.objID*1 + 1); //12
--
Gavin Kistner @ Refinery, Inc.
gavin@refinery.com
work: +1.303.444.1777
cell: +1.303.641.1521
Received on Monday, 6 October 2003 14:12:58 UTC