javascript - This code doesn't work in IE -


hi have jquery/js script. takes encoded url string , parses , saves variable values variables.

basically 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 script want. url string:

/autopop.html?email=test%40test.com&lastname=test+last&&firstname=+test+first 

i values:

email = test%40test.com  lastname = test+last  firstname = +test+first 

what want auto-populate form on same page information. (i know you're thinking server-side script better solution boss says don't have access that, trust me, i've tried)

long story short, here's rest of 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 job done. except 1 browser. ie.

ie doesn't support decodeuricomponent or i've read. in case, tried using other functions decodeuri , escape producing unwanted results.

my google searches have yielded nothing but, semi-interesting articles (totally off-topic thought i'd share that).

no solutions. can shed light? how make work on ie?

you have read wrong, decodeuricomponent works fine in ie, in ie6.

however, trim doesn't work in ie browsers prior ie 9 , that's causing script crash.

for working alternative, see accepted answer here: .trim() in javascript not working in ie
or use jquery trim() method you're using jquery anyway.


Comments

Popular posts from this blog

php - What is the difference between $_SERVER['PATH_INFO'] and $_SERVER['ORIG_PATH_INFO']? -

fortran - Function return type mismatch -

queue - mq_receive: message too long -