[SWFObject] Bug in getQueryParamValue() function. Please fix ASAP.

Aran Rhee aran.rhee at qdc.net.au
Tue May 30 21:17:11 PDT 2006


Geoff.
 
I believe I have found a bug in your query params function with swfObject.
The way you are returning values from your search means that it will return
the value of the 1st parameter which contains the substring of the name
passed into getQueryParamValue(), not necessarily the actual value you want!

 
e.g. 
 
somepage.html?myEmailName=aaaa at aaaa.com&Email=xxxx at xxxx.com
<mailto:somepage.html?myEmailName=aaaa at aaaa.com&Email=xxxx at xxxx.com> 
 
getQueryParamValue('Email');
 
will actually return  <mailto:aaaa at aaaa.com> aaaa at aaaa.com, as the value as
"Email" was found in the 1st param name string.
 
 
I think you need to actually split the params into an array and do a full
text match. I wrote the below as a fix for myself quickly, and itdesigned to
be readable, not compact, but you get the idea.
 
 function getRequestParameter (key)
 {
  var q = document.location.search || document.location.hash;
  if(q)
  {
   var qArray = q.substring(1).split("&");
   var len = qArray.length;
   for (i = 0; i<len; i++)
   {
    var pair = qArray[i];
    var splitIndex = pair.indexOf("=");
    var paramName = pair.substring(0, splitIndex);
    var paramValue= pair.substring((splitIndex+1));
    if (paramName == key)
    {
     return paramValue;
    }
   }
   return "";
  }
  return "";
 }
 
 
You could compact it like:
 
function getRequestParameter (key) {
  var q = document.location.search || document.location.hash;
  if(q) {
   var qArray = q.substring(1).split("&");
   for (i = 0; i<qArray.length; i++) {
    if (qArray[i].substring(0, qArray[i].indexOf("=")) == key) return
qArray[i].substring((qArray[i].indexOf("=")+1));
   }
   return "";
  }
  return "";
 }
 
 
 
 
Cheers,
 
Aran
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.deconcept.com/pipermail/swfobject-deconcept.com/attachments/20060531/ab153c70/attachment-0004.htm>


More information about the Swfobject mailing list