Hi so I have this jQuery/JS script. That basically takes an encoded URL string and parses it and saves variable values into variables.
Basically what PHP's $_GET does.
function getUrlVars()
{
var map = {};
var parts = window.location.search.replace(/[?&]+([^=&]+)(=[^&]*)?/gi,
function(m,key,value)
{ map[key] = (value === undefined) ? true : value.substring(1); });
return map;
}
Basically this script does what I want. From this URL string:
/autopop.html?Email=test%40test.com&LastName=Test+last&&FirstName=+Test+First
I get the values:
Email = test%40test.com
LastName = Test+last
FirstName = +Test+First
What I want to do is Auto-populate a form on this same page with this information. (I know what you're thinking a server-side script would be a better solution but the boss says we don't have access to that, trust me, I've tried)
Long story short, here's the rest of my code:
var keys = getUrlVars();
$(document).ready(function(){
var fname = keys['FirstName'].replace(/\+/g , " ").trim();
var lname = keys['LastName'].replace(/\+/g , " ").trim();
var email = decodeURIComponent(keys['Contact0Email'].replace(/\+/g , " ")).trim();
$("#Email").val(email);
$("#FirstName").val(fname);
$("#LastName").val(lname);
});
This code gets the job done. All except for one browser. IE.
IE doesn't support decodeURIComponent
or so I've read. In any case, I tried using other functions like decodeURI
and escape
all producing unwanted results.
My google searches have yielded nothing but, semi-interesting articles (totally off-topic but thought I'd just share that).
No solutions. Can anyone shed some light? How do I make this work on IE?