开发者

Curly Brackets Converted to Hexidecimal when using URL.Document or window.location.href

Would like to take document.URL, find the string with curly brackets, remove the curly brackets, and show just the string that was inside the curly brackets. However, it seems that document.URL or window.location.href convert the curly brackets to hexidecimal values (%7B & %7D) and then I can't match against the actual {string}. Any help would be appreciated.

  var txt = document.URL; // My URL is something like http://site.com/somepage&value0={string}
  v开发者_运维技巧ar re1='.*?';    // Non-greedy match on filler
  var re2='(\\{.*?\\})';    // Curly Braces 1

  var p = new RegExp(re1+re2,["i"]);
  var m = p.exec(txt);

  if (m != null)
  {
      var cbraces1=m[1];
      document.write(cbraces1.replace("{","").replace("}",""));
  }


Use decodeURI(document.URL) first.

var txt = decodeURI(document.URL);


unescape('%7B & %7D');

this should help

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜