156

最高の JavaScript URL デコード ユーティリティは何ですか? エンコーディングもいいでしょうし、jQuery との連携もおまけです。

4

9 に答える 9

239

これは完全な関数です(PHPJSから取得):

function urldecode(str) {
   return decodeURIComponent((str+'').replace(/\+/g, '%20'));
}
于 2010-12-16T08:03:01.027 に答える
220

encodeURIComponent()decodeURIComponent()も使用しました。

于 2010-11-27T17:34:10.433 に答える
9
decodeURIComponent(mystring);

次のコードを使用して、渡されたパラメーターを取得できます。

//parse URL to get values: var i = getUrlVars()["i"];
function getUrlVars() {
    var vars = [], hash;
    var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
    for (var i = 0; i < hashes.length; i++) {
        hash = hashes[i].split('=');
        vars.push(hash[0]);
        vars[hash[0]] = hash[1];
    }
    return vars;
}

または、このワンライナーでパラメーターを取得します。

location.search.split("your_parameter=")[1]
于 2011-04-19T18:12:58.647 に答える
9

これを使って

unescape(str);

私は優れた JS プログラマーではありません。

于 2013-02-13T12:51:09.507 に答える
3
//How decodeURIComponent Works

function proURIDecoder(val)
{
  val=val.replace(/\+/g, '%20');
  var str=val.split("%");
  var cval=str[0];
  for (var i=1;i<str.length;i++)
  {
    cval+=String.fromCharCode(parseInt(str[i].substring(0,2),16))+str[i].substring(2);
  }

  return cval;
}

document.write(proURIDecoder(window.location.href));
于 2013-01-11T06:40:41.707 に答える
0

これが私が使用したものです:

JavaScript の場合:

var url = "http://www.mynewsfeed.com/articles/index.php?id=17";
var encoded_url = encodeURIComponent(url);

var decoded_url = decodeURIComponent(encoded_url);

PHP の場合:

$url = "http://www.mynewsfeed.com/articles/index.php?id=17";
$encoded_url = url_encode(url);

$decoded_url = url_decode($encoded_url);

オンラインで試すこともできます: http://www.mynewsfeed.x10.mx/articles/index.php?id=17

于 2015-07-15T13:03:36.747 に答える